wallaby-cash 2.3.4 → 2.3.6
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/index.cjs.js +34 -142
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +32 -142
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +32 -142
- package/dist/index.js.map +1 -1
- package/dist/lib/wallet/wallet-data.service.d.ts +1 -1
- package/dist/lib/wallet/wallet.service.d.ts +4 -7
- package/dist/package.json +3 -1
- package/dist/routes/swap.d.ts +1 -3
- package/dist/routes/wallet.d.ts +1 -1
- package/dist/types/wallet.d.ts +1 -15
- package/package.json +3 -1
package/dist/index.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as algosdk from 'algosdk';
|
|
2
|
+
import * as bip39 from 'bip39';
|
|
2
3
|
import log from 'loglevel';
|
|
3
4
|
import { AES, enc } from 'crypto-js';
|
|
4
5
|
import { jwtDecode } from 'jwt-decode';
|
|
5
6
|
import * as NativeWebAuthn from 'react-native-passkey';
|
|
6
7
|
import { omit } from 'lodash';
|
|
7
8
|
import { atob, toUint8Array } from 'js-base64';
|
|
9
|
+
import { v4 } from 'uuid';
|
|
8
10
|
|
|
9
11
|
/******************************************************************************
|
|
10
12
|
Copyright (c) Microsoft Corporation.
|
|
@@ -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.6" ;
|
|
579
581
|
|
|
580
582
|
/**
|
|
581
583
|
* Storage keys adapter for Storage interface across different platforms.
|
|
@@ -7172,8 +7174,8 @@ const WalletRoutes = {
|
|
|
7172
7174
|
requiresAccessToken: false,
|
|
7173
7175
|
},
|
|
7174
7176
|
getTokenBalance: {
|
|
7175
|
-
fullPath: ({ address,
|
|
7176
|
-
return (`/query/assets/balance?address=${address}&assetSymbol=${
|
|
7177
|
+
fullPath: ({ address, assetSymbol, chainName, tokenStandard }) => {
|
|
7178
|
+
return (`/query/assets/balance?address=${address}&assetSymbol=${assetSymbol}` +
|
|
7177
7179
|
`${tokenStandard ? `&tokenType=${tokenStandard}` : ''}` +
|
|
7178
7180
|
`${chainName ? `&chainName=${chainName}` : ''}`);
|
|
7179
7181
|
},
|
|
@@ -7359,17 +7361,17 @@ const TransactionsRoutes = {
|
|
|
7359
7361
|
|
|
7360
7362
|
const SwapRoutes = {
|
|
7361
7363
|
getQuote: {
|
|
7362
|
-
fullPath: ({ walletId }) => `/
|
|
7364
|
+
fullPath: ({ walletId }) => `/wallets/${walletId}/swap/quote`,
|
|
7363
7365
|
method: RequestMethod.Post,
|
|
7364
7366
|
requiresAccessToken: true,
|
|
7365
7367
|
},
|
|
7366
7368
|
executeSwap: {
|
|
7367
|
-
fullPath:
|
|
7369
|
+
fullPath: '/wallets/execute-swap',
|
|
7368
7370
|
method: RequestMethod.Post,
|
|
7369
7371
|
requiresAccessToken: true,
|
|
7370
7372
|
},
|
|
7371
7373
|
getSwaps: {
|
|
7372
|
-
fullPath: ({ walletId }) => `/
|
|
7374
|
+
fullPath: ({ walletId }) => `/wallets/${walletId}/swaps`,
|
|
7373
7375
|
method: RequestMethod.Get,
|
|
7374
7376
|
requiresAccessToken: true,
|
|
7375
7377
|
},
|
|
@@ -9136,21 +9138,7 @@ class WalletService extends Base {
|
|
|
9136
9138
|
},
|
|
9137
9139
|
});
|
|
9138
9140
|
if (exportOptions.algorandSeedPhrase) {
|
|
9139
|
-
|
|
9140
|
-
standardSeedPhrase: decryptedSeedPhrase,
|
|
9141
|
-
authenticationOptions,
|
|
9142
|
-
walletId,
|
|
9143
|
-
});
|
|
9144
|
-
decryptedAlgorandSeedPhrase = await this.cipher.displayDataFromServer({
|
|
9145
|
-
encryptedData: algorandSeedPhrase.convertedEncryptedSeed,
|
|
9146
|
-
encryptedDevicePrivateKey: parsedDevicePrivateKey,
|
|
9147
|
-
options: {
|
|
9148
|
-
authType: this.deviceAuthType,
|
|
9149
|
-
password: authenticationOptions.password,
|
|
9150
|
-
salt: authenticationOptions.user.clientSalt,
|
|
9151
|
-
prfValue: authenticationOptions.prfValue,
|
|
9152
|
-
},
|
|
9153
|
-
});
|
|
9141
|
+
decryptedAlgorandSeedPhrase = this.getAlgorandSeedPhrase(decryptedSeedPhrase);
|
|
9154
9142
|
if (!decryptedAlgorandSeedPhrase) {
|
|
9155
9143
|
throw new WallabyError({
|
|
9156
9144
|
message: 'Something went wrong decrypting algorand seed phrase.',
|
|
@@ -9194,21 +9182,7 @@ class WalletService extends Base {
|
|
|
9194
9182
|
decryptionKey: decryptedDevicePrivateKey,
|
|
9195
9183
|
});
|
|
9196
9184
|
if (exportOptions.algorandSeedPhrase) {
|
|
9197
|
-
|
|
9198
|
-
standardSeedPhrase: decryptedSeedPhrase,
|
|
9199
|
-
authenticationOptions,
|
|
9200
|
-
walletId,
|
|
9201
|
-
});
|
|
9202
|
-
decryptedAlgorandSeedPhrase = await this.cipher.displayDataFromServer({
|
|
9203
|
-
encryptedData: algorandSeedPhrase.convertedEncryptedSeed,
|
|
9204
|
-
encryptedDevicePrivateKey: parsedDevicePrivateKey,
|
|
9205
|
-
options: {
|
|
9206
|
-
authType: this.deviceAuthType,
|
|
9207
|
-
password: authenticationOptions.password,
|
|
9208
|
-
salt: authenticationOptions.user.clientSalt,
|
|
9209
|
-
prfValue: authenticationOptions.prfValue,
|
|
9210
|
-
},
|
|
9211
|
-
});
|
|
9185
|
+
decryptedAlgorandSeedPhrase = this.getAlgorandSeedPhrase(decryptedSeedPhrase);
|
|
9212
9186
|
}
|
|
9213
9187
|
}
|
|
9214
9188
|
}
|
|
@@ -9569,109 +9543,23 @@ class WalletService extends Base {
|
|
|
9569
9543
|
*
|
|
9570
9544
|
* @public
|
|
9571
9545
|
* Convert BIP39 Standard seed phrase to Algorand fixed 25 words mnemonic phrase
|
|
9572
|
-
* @param {
|
|
9573
|
-
*
|
|
9574
|
-
* - {string} walletId - The Wallaby wallet ID.
|
|
9575
|
-
* - {AuthenticationResponse} authenticationOptions - The authentication options carried from the authentication request (`signIn` | `signUp`)
|
|
9576
|
-
* @returns {ConvertMnemonicSeedPhraseResponse} The mnemonic seed phrase has been converted successfully.
|
|
9546
|
+
* @param {string} bip39Mnemonic - The decrypted standard seed phrase (bip32 standard 24 words mnemonic) to be transformed.
|
|
9547
|
+
* @returns {string} The Algorand fixed 25 words mnemonic phrase.
|
|
9577
9548
|
*/
|
|
9578
|
-
|
|
9549
|
+
getAlgorandSeedPhrase(bip39Mnemonic) {
|
|
9579
9550
|
try {
|
|
9580
|
-
const
|
|
9581
|
-
const
|
|
9582
|
-
|
|
9583
|
-
|
|
9584
|
-
message: 'Device private key could not be found',
|
|
9585
|
-
statusCode: 404,
|
|
9586
|
-
errorCode: ErrorResponseCodes.sdk_private_key_not_found,
|
|
9587
|
-
});
|
|
9588
|
-
const parsedEncryptedDevicePrivateKey = safeJsonParse(storedEncryptedDevicePrivateKey);
|
|
9589
|
-
if (this.deviceAuthType === AuthType.Password && input.authenticationOptions.password) {
|
|
9590
|
-
try {
|
|
9591
|
-
await this.handleUpdateToV2({
|
|
9592
|
-
password: input.authenticationOptions.password,
|
|
9593
|
-
walletId: input.walletId,
|
|
9594
|
-
});
|
|
9595
|
-
}
|
|
9596
|
-
catch (error) {
|
|
9597
|
-
logger.error('SDK::WalletService::getAlgorandSeedPhrase::handleUpdateToV2::error', error);
|
|
9598
|
-
throw new WallabyError({
|
|
9599
|
-
message: 'Error accessing user wallet on this device. Please ensure the password is correct and try again.',
|
|
9600
|
-
statusCode: 500,
|
|
9601
|
-
errorCode: ErrorResponseCodes.sdk_unknown_error,
|
|
9602
|
-
});
|
|
9603
|
-
}
|
|
9604
|
-
}
|
|
9605
|
-
let wallabyBoundSeedPhrase;
|
|
9606
|
-
if (standardSeedPhrase) {
|
|
9607
|
-
const encryptedSeed = await this.cipher.encrypt({
|
|
9608
|
-
data: standardSeedPhrase,
|
|
9609
|
-
encryptionKey: user.wallabyAuthPubKey,
|
|
9610
|
-
});
|
|
9611
|
-
wallabyBoundSeedPhrase = encryptedSeed;
|
|
9612
|
-
}
|
|
9613
|
-
else {
|
|
9614
|
-
const storedEncryptedStandardSeedPhrase = await this.localStorageService.fetch(LocalStorageItems.EncryptedStandardSeedPhrase, {
|
|
9615
|
-
walletId: input.walletId,
|
|
9616
|
-
});
|
|
9617
|
-
if (!storedEncryptedStandardSeedPhrase) {
|
|
9618
|
-
throw new WallabyError({
|
|
9619
|
-
message: 'Device is missing required information, please import your wallet on this device before proceeding.',
|
|
9620
|
-
statusCode: 404,
|
|
9621
|
-
errorCode: ErrorResponseCodes.sdk_seed_phrase_not_found,
|
|
9622
|
-
});
|
|
9623
|
-
}
|
|
9624
|
-
const parsedEncryptedStandardSeedPhrase = safeJsonParse(storedEncryptedStandardSeedPhrase);
|
|
9625
|
-
wallabyBoundSeedPhrase = await this.cipher.prepareStoredDataForTransport({
|
|
9626
|
-
storedEncryptedData: parsedEncryptedStandardSeedPhrase,
|
|
9627
|
-
encryptedDevicePrivateKey: parsedEncryptedDevicePrivateKey,
|
|
9628
|
-
wallabyPublicKey: user.wallabyAuthPubKey,
|
|
9629
|
-
options: {
|
|
9630
|
-
authType: this.deviceAuthType,
|
|
9631
|
-
password,
|
|
9632
|
-
prfValue,
|
|
9633
|
-
salt: clientSalt,
|
|
9634
|
-
},
|
|
9635
|
-
});
|
|
9636
|
-
}
|
|
9637
|
-
const credentialsKeyPair = await this.cipher.getCredentialsKeyPair({
|
|
9638
|
-
authType: this.deviceAuthType,
|
|
9639
|
-
password,
|
|
9640
|
-
salt: clientSalt,
|
|
9641
|
-
prfValue,
|
|
9642
|
-
});
|
|
9643
|
-
const decryptedDevicePrivateKey = await this.cipher.decrypt({
|
|
9644
|
-
cipherText: parsedEncryptedDevicePrivateKey,
|
|
9645
|
-
decryptionKey: credentialsKeyPair.privateKey,
|
|
9646
|
-
});
|
|
9647
|
-
if (!decryptedDevicePrivateKey) {
|
|
9648
|
-
throw new WallabyError({
|
|
9649
|
-
message: 'Failed to decrypt device private key',
|
|
9650
|
-
statusCode: 500,
|
|
9651
|
-
errorCode: ErrorResponseCodes.sdk_private_key_decryption_failed,
|
|
9652
|
-
});
|
|
9653
|
-
}
|
|
9654
|
-
const clientAuthPubKey = publicKeyByPrivateKey(decryptedDevicePrivateKey);
|
|
9655
|
-
const reference = v4();
|
|
9656
|
-
const signatureMessage = await this.authService.getSignature({
|
|
9657
|
-
publicKey: clientAuthPubKey,
|
|
9658
|
-
privateKey: decryptedDevicePrivateKey,
|
|
9659
|
-
});
|
|
9660
|
-
const { message, signature } = signatureMessage;
|
|
9661
|
-
const response = await this.request(WalletRoutes.convertMnemonicSeedPhrase, {
|
|
9662
|
-
payload: {
|
|
9663
|
-
reference,
|
|
9664
|
-
signature,
|
|
9665
|
-
message,
|
|
9666
|
-
clientAuthPubKey,
|
|
9667
|
-
encryptedSeed: wallabyBoundSeedPhrase,
|
|
9668
|
-
},
|
|
9669
|
-
});
|
|
9670
|
-
return response;
|
|
9551
|
+
const seedBuffer = bip39.mnemonicToSeedSync(bip39Mnemonic);
|
|
9552
|
+
const seed = seedBuffer.slice(0, 32);
|
|
9553
|
+
const convertedSeedPhrase = algosdk.mnemonicFromSeed(seed);
|
|
9554
|
+
return convertedSeedPhrase;
|
|
9671
9555
|
}
|
|
9672
9556
|
catch (error) {
|
|
9673
9557
|
logger.error('SDK::Wallet::getAlgorandSeedPhrase::error', error);
|
|
9674
|
-
throw
|
|
9558
|
+
throw new WallabyError({
|
|
9559
|
+
message: error instanceof Error ? error.message : 'Failed to convert seed phrase to Algorand mnemonic.',
|
|
9560
|
+
statusCode: 500,
|
|
9561
|
+
errorCode: ErrorResponseCodes.sdk_unknown_error,
|
|
9562
|
+
});
|
|
9675
9563
|
}
|
|
9676
9564
|
}
|
|
9677
9565
|
/**
|
|
@@ -10605,9 +10493,9 @@ class WalletDataService extends Base {
|
|
|
10605
10493
|
* @param { BlockchainName } chainName the chain name enum. i.e. 'ETHEREUM', 'BITCOIN'
|
|
10606
10494
|
* @returns { TokenBalance } Balance of the token
|
|
10607
10495
|
*/
|
|
10608
|
-
async getTokenBalance({ address,
|
|
10496
|
+
async getTokenBalance({ address, assetSymbol, tokenStandard, chainName }) {
|
|
10609
10497
|
try {
|
|
10610
|
-
if (!address || !
|
|
10498
|
+
if (!address || !assetSymbol || (!chainName && !tokenStandard)) {
|
|
10611
10499
|
throw new WallabyError({
|
|
10612
10500
|
message: 'Missing required parameters',
|
|
10613
10501
|
statusCode: 400,
|
|
@@ -10615,7 +10503,7 @@ class WalletDataService extends Base {
|
|
|
10615
10503
|
});
|
|
10616
10504
|
}
|
|
10617
10505
|
const response = await this.request(WalletRoutes.getTokenBalance, {
|
|
10618
|
-
payload: { address,
|
|
10506
|
+
payload: { address, assetSymbol, chainName, tokenStandard },
|
|
10619
10507
|
});
|
|
10620
10508
|
return response;
|
|
10621
10509
|
}
|
|
@@ -11290,11 +11178,10 @@ class Swap extends Base {
|
|
|
11290
11178
|
}
|
|
11291
11179
|
const { deviceAuthPublicKey, signatureMessage, readyForTransportSeedPhrase, sharesEncryptedWithWallabyPubKey, hasShares } = await this.prepareSwapAuth(authenticationOptions, walletId);
|
|
11292
11180
|
let swapResponse;
|
|
11293
|
-
// Build path with walletId, but exclude it from request body
|
|
11294
|
-
const routePayload = { walletId };
|
|
11295
11181
|
if (readyForTransportSeedPhrase) {
|
|
11296
|
-
swapResponse = await this.request(Object.assign(Object.assign({}, SwapRoutes.executeSwap), { fullPath: SwapRoutes.executeSwap.fullPath
|
|
11182
|
+
swapResponse = await this.request(Object.assign(Object.assign({}, SwapRoutes.executeSwap), { fullPath: SwapRoutes.executeSwap.fullPath }), {
|
|
11297
11183
|
payload: {
|
|
11184
|
+
walletId,
|
|
11298
11185
|
quoteId,
|
|
11299
11186
|
message: signatureMessage.message,
|
|
11300
11187
|
signature: signatureMessage.signature,
|
|
@@ -11304,8 +11191,9 @@ class Swap extends Base {
|
|
|
11304
11191
|
});
|
|
11305
11192
|
}
|
|
11306
11193
|
else if (hasShares) {
|
|
11307
|
-
swapResponse = await this.request(Object.assign(Object.assign({}, SwapRoutes.executeSwap), { fullPath: SwapRoutes.executeSwap.fullPath
|
|
11194
|
+
swapResponse = await this.request(Object.assign(Object.assign({}, SwapRoutes.executeSwap), { fullPath: SwapRoutes.executeSwap.fullPath }), {
|
|
11308
11195
|
payload: {
|
|
11196
|
+
walletId,
|
|
11309
11197
|
quoteId,
|
|
11310
11198
|
message: signatureMessage.message,
|
|
11311
11199
|
signature: signatureMessage.signature,
|
|
@@ -11793,6 +11681,7 @@ class Transactions extends Base {
|
|
|
11793
11681
|
if (readyForTransportSeedPhrase) {
|
|
11794
11682
|
transferResponse = await this.request(TransactionsRoutes.transfer, {
|
|
11795
11683
|
payload: {
|
|
11684
|
+
walletId,
|
|
11796
11685
|
message: signatureMessage.message,
|
|
11797
11686
|
signature: signatureMessage.signature,
|
|
11798
11687
|
clientAuthPubKey: deviceAuthPublicKey,
|
|
@@ -11810,6 +11699,7 @@ class Transactions extends Base {
|
|
|
11810
11699
|
else if (hasShares) {
|
|
11811
11700
|
transferResponse = await this.request(TransactionsRoutes.transferWithShares, {
|
|
11812
11701
|
payload: {
|
|
11702
|
+
walletId,
|
|
11813
11703
|
message: signatureMessage.message,
|
|
11814
11704
|
signature: signatureMessage.signature,
|
|
11815
11705
|
clientAuthPubKey: deviceAuthPublicKey,
|