wallaby-cash 1.3.2 → 1.3.4

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.
Files changed (44) hide show
  1. package/dist/base.d.ts +20 -1
  2. package/dist/index.d.ts +1 -1
  3. package/dist/index.esm.js +1 -1
  4. package/dist/index.esm.js.map +1 -1
  5. package/dist/index.js +1 -1
  6. package/dist/index.js.map +1 -1
  7. package/dist/index.umd.js +1 -1
  8. package/dist/index.umd.js.map +1 -1
  9. package/dist/lib/auth/index.d.ts +16 -10
  10. package/dist/lib/transactions/index.d.ts +5 -5
  11. package/dist/lib/utils/index.d.ts +29 -9
  12. package/dist/lib/utils/utils.d.ts +22 -13
  13. package/dist/lib/wallet/index.d.ts +34 -11
  14. package/dist/routes/auth.d.ts +11 -6
  15. package/dist/routes/merchants.d.ts +7 -7
  16. package/dist/routes/system.d.ts +4 -4
  17. package/dist/routes/transactions.d.ts +13 -6
  18. package/dist/routes/wallet.d.ts +15 -10
  19. package/dist/tests/data/user.d.ts +3 -2
  20. package/dist/types/auth.d.ts +5 -10
  21. package/dist/types/common.d.ts +5 -1
  22. package/dist/types/transactions.d.ts +2 -2
  23. package/dist/types/wallet.d.ts +13 -6
  24. package/package.json +2 -2
  25. package/src/base.ts +40 -8
  26. package/src/index.ts +2 -2
  27. package/src/lib/auth/index.ts +49 -24
  28. package/src/lib/transactions/index.ts +7 -7
  29. package/src/lib/utils/index.ts +77 -19
  30. package/src/lib/utils/utils.ts +96 -36
  31. package/src/lib/wallet/index.ts +209 -35
  32. package/src/routes/auth.ts +11 -6
  33. package/src/routes/merchants.ts +7 -7
  34. package/src/routes/system.ts +4 -4
  35. package/src/routes/transactions.ts +23 -6
  36. package/src/routes/wallet.ts +15 -10
  37. package/src/tests/auth.spec.ts +26 -24
  38. package/src/tests/data/user.ts +3 -2
  39. package/src/tests/utils.spec.ts +9 -13
  40. package/src/tests/wallet.spec.ts +12 -7
  41. package/src/types/auth.ts +5 -11
  42. package/src/types/common.ts +6 -1
  43. package/src/types/transactions.ts +2 -2
  44. package/src/types/wallet.ts +14 -6
@@ -1,6 +1,6 @@
1
1
  import { config, testUser } from './data';
2
2
  import { setEncryptedPrivateKey, getAccessToken } from '../lib/utils/utils';
3
- import { SignUpResponse, SignatureMessageResponse, User } from '../types';
3
+ import { AuthResponse, SignatureMessageResponse, User } from '../types';
4
4
  import Wallaby from '../index';
5
5
  import mockAxios from 'axios';
6
6
  import axios from 'axios';
@@ -8,7 +8,7 @@ import axios from 'axios';
8
8
  describe('Auth Functions', () => {
9
9
  const {
10
10
  id,
11
- hashKey,
11
+ password,
12
12
  firstName,
13
13
  lastName,
14
14
  email,
@@ -24,34 +24,36 @@ describe('Auth Functions', () => {
24
24
  const wallaby = new Wallaby(config);
25
25
  const mockAxiosSpy = jest.spyOn(mockAxios, 'post');
26
26
  afterEach(() => {
27
- mockAxiosSpy.mockRestore()
28
- })
27
+ mockAxiosSpy.mockRestore();
28
+ });
29
29
  describe('signatureMessage()', () => {
30
30
  beforeEach(() => {
31
- mockAxiosSpy.mockImplementationOnce(() => Promise.resolve({ data: { message } }))
32
- })
31
+ mockAxiosSpy.mockImplementationOnce(() => Promise.resolve({ data: { message } }));
32
+ });
33
33
  afterAll(() => {
34
- mockAxiosSpy.mockRestore()
35
- })
34
+ mockAxiosSpy.mockRestore();
35
+ });
36
36
  it('Returns undefined if hash key is not provided', async () => {
37
- const emtpyHashKey = '';
38
- const response = await wallaby.auth.signatureMessage({ hashKey: emtpyHashKey, userId: id });
39
- expect(response).toBeUndefined();
37
+ const emtpypassword = '';
38
+
39
+ await expect(wallaby.auth.signatureMessage({ password: emtpypassword, userId: id })).rejects.toThrow(
40
+ 'Please provide a password',
41
+ );
40
42
  });
41
43
  it('Creates new key pair if private key is not found', async () => {
42
- const response = await wallaby.auth.signatureMessage({ hashKey, userId: id });
43
- console.log('response private key is not found', response);
44
+ const response = await wallaby.auth.signatureMessage({ password, userId: id });
45
+
44
46
  expect(response?.clientAuthPubKey).not.toEqual(testUser.publicKey);
45
47
  expect(response?.decryptedClientAuthPrivKey).not.toEqual(testUser.privateKey);
46
48
  });
47
49
  it('Fetches private key from local storage successfully', async () => {
48
- setEncryptedPrivateKey(testUser.id, testUser.privateKey, testUser.hashKey);
49
- const response = await wallaby.auth.signatureMessage({ hashKey, userId: id });
50
+ setEncryptedPrivateKey(testUser.id, testUser.privateKey, testUser.password);
51
+ const response = await wallaby.auth.signatureMessage({ password, userId: id });
50
52
  expect(response?.decryptedClientAuthPrivKey).toEqual(testUser.privateKey);
51
53
  expect(response?.clientAuthPubKey).toEqual(testUser.publicKey);
52
54
  });
53
55
  it('Returns all response properties', async () => {
54
- const response = await wallaby.auth.signatureMessage({ hashKey, userId: id });
56
+ const response = await wallaby.auth.signatureMessage({ password, userId: id });
55
57
  const { message, decryptedClientAuthPrivKey, clientAuthPubKey, hashedMessage, signature } =
56
58
  response as SignatureMessageResponse;
57
59
  expect(decryptedClientAuthPrivKey).toBeDefined();
@@ -88,7 +90,7 @@ describe('Auth Functions', () => {
88
90
  accessToken: testAccessToken,
89
91
  },
90
92
  });
91
- })
93
+ });
92
94
  // signUpSpy.mockImplementation(() => {
93
95
  // return Promise.resolve({
94
96
 
@@ -96,21 +98,21 @@ describe('Auth Functions', () => {
96
98
  // })
97
99
  });
98
100
  it('Calls signatureMessage to get a new message', async () => {
99
- await wallaby.auth.signUp({ hashKey, firstName, lastName, email });
101
+ await wallaby.auth.signUp({ password, firstName, lastName, email });
100
102
 
101
103
  expect(wallaby.auth.signatureMessage).toHaveBeenCalled();
102
104
  });
103
105
  it('Has access token in response and stores it successfully', async () => {
104
- const response = await wallaby.auth.signUp({ hashKey, firstName, lastName, email });
105
- const { accessToken } = response as SignUpResponse;
106
+ const response = await wallaby.auth.signUp({ password, firstName, lastName, email });
107
+ const { accessToken } = response as AuthResponse;
106
108
  expect(accessToken).toEqual(testAccessToken);
107
- expect(getAccessToken(id)).toBeDefined()
109
+ expect(getAccessToken(id)).toBeDefined();
108
110
  });
109
111
  it('Has user Wallaby ID and Wallaby AuthPubKey', async () => {
110
- const response = await wallaby.auth.signUp({ hashKey, firstName, lastName, email });
111
- const { user } = response as SignUpResponse;
112
+ const response = await wallaby.auth.signUp({ password, firstName, lastName, email });
113
+ const { user } = response as AuthResponse;
112
114
  expect(user.wallabyAuthPubKey).toEqual(wallabyAuthPublicKey);
113
- expect(user.id).toBe(wallabyUserId)
115
+ expect(user.id).toBe(wallabyUserId);
114
116
  });
115
117
  });
116
118
  });
@@ -6,8 +6,9 @@ export const testUser = {
6
6
  firstName: 'Joanna',
7
7
  lastName: 'Smith',
8
8
  email: 'joanna.smith@yopmail.com',
9
- hashKey: '16charencryption',
10
- wrongHashKey: '17charencryption!',
9
+ password: '16charencryption',
10
+ salt: 'SomeSaltyStringThatIsUsedInEncryption',
11
+ wrongPassword: '17charencryption!',
11
12
  message: 'c25d687f94ab48bfa87baeef4a2741ab',
12
13
  hashedMessage: '0x721edfb991965324620d2259fd1e0e1f19f36eb46d9cd8ada68686bc3f7cc5d1',
13
14
  signature: '0x9b765cea1d8fec0c1c4f51567dfcd5554fc0fad82074049f10ad5d6d1db46d253155f7793d9f88d55ff3fce28c0112528fde02962eab9e04089715e048ae9ce51b',
@@ -9,18 +9,12 @@ import {
9
9
  getDecryptedPrivateKey,
10
10
  setEncryptedSeedPhrase,
11
11
  getEncryptedSeedPhrase,
12
- validatePassword,
13
12
  } from '../lib/utils/utils';
14
13
  import { SeedPhraseType } from '../types';
15
14
  import { testUser } from './data';
16
- // import { LocalStorage } from 'node-localstorage';
17
-
18
- // back to this temp solution
19
- // const tempLocalStorage = new LocalStorage(`${__dirname}/../../tests/temp`);
20
- // const tempLocalStorage = require('./__mocks__/localStorageMock');
21
15
 
22
16
  describe('Utilities functions', () => {
23
- const { id, hashKey, wrongHashKey, seedPhrase, privateKey, publicKey } = testUser;
17
+ const { id, password, salt, wrongPassword, seedPhrase, privateKey, publicKey } = testUser;
24
18
 
25
19
  describe('WallabyAuthPublicKey', () => {
26
20
  const setterResult = setWallabyAuthPubKey(id, publicKey);
@@ -34,7 +28,7 @@ describe('Utilities functions', () => {
34
28
  });
35
29
 
36
30
  describe('ClientAuthPrivateKey', () => {
37
- const setterResult = setEncryptedPrivateKey(id, privateKey, hashKey);
31
+ const setterResult = setEncryptedPrivateKey(id, privateKey, password);
38
32
  const getterResult = getEncryptedPrivateKey(id);
39
33
  it('stores key to local storage and returns true', () => {
40
34
  expect(setterResult).toBeTruthy();
@@ -45,21 +39,23 @@ describe('Utilities functions', () => {
45
39
  it('stores client auth private key in local storage', () => {
46
40
  expect(getterResult).toBeDefined();
47
41
  });
48
- it('decrypts private key if hashKey is correct', () => {
49
- const decryptedResult = getDecryptedPrivateKey(id, hashKey);
42
+ it('decrypts private key if password is correct', () => {
43
+ const decryptedResult = getDecryptedPrivateKey(id, password);
50
44
  expect(decryptedResult).toBeDefined();
51
45
  expect(decryptedResult).toEqual(privateKey);
52
46
  });
53
- it('returns an error if hashKey is incorrect', () => {
47
+ it('returns an error if password is incorrect', () => {
48
+ localStorage.removeItem(`encryptedPrivateKey_${id}`);
54
49
  localStorage.removeItem(`${process.env.NODE_ENV}-client-auth-private-key-${id}`);
55
- const decryptedResult = getDecryptedPrivateKey(id, wrongHashKey);
50
+ const decryptedResult = getDecryptedPrivateKey(id, wrongPassword);
56
51
  expect(decryptedResult).toBeUndefined();
57
52
  });
58
53
  });
59
54
 
60
55
  describe('EncryptedSeedPhrase storing and fetching', () => {
61
56
  it('stores seedPhrase in local storage', async () => {
62
- const seedPhraseIsSet = await setEncryptedSeedPhrase(id, publicKey, seedPhrase, SeedPhraseType.Standard);
57
+ const seedPhraseIsSet = await setEncryptedSeedPhrase(id, publicKey, seedPhrase, SeedPhraseType.Standard, salt, password);
58
+ console.log('seedPhraseIsSet', seedPhraseIsSet);
63
59
  expect(seedPhraseIsSet).toBeTruthy();
64
60
  });
65
61
  it('encrypts seedPhrase before storing it', async () => {
@@ -4,7 +4,7 @@ import { SeedPhraseType } from '../types';
4
4
  import { config, testUser } from './data';
5
5
  const wallaby = new Wallaby(config);
6
6
 
7
- const { id, hashKey, testAccessToken, privateKey, seedPhrase, wallabyAuthPublicKey, publicKey } = testUser;
7
+ const { id, password, testAccessToken, privateKey, seedPhrase, wallabyAuthPublicKey, publicKey, salt } = testUser;
8
8
 
9
9
  describe('Wallet Functions', () => {
10
10
  describe('getTokenBalance()', () => {
@@ -12,18 +12,23 @@ describe('Wallet Functions', () => {
12
12
  expect(true).toBeTruthy();
13
13
  });
14
14
  });
15
- describe('clearWalletData()', () => {
15
+ describe('clearDevice()', () => {
16
16
  it('clears wallet data from local storage', async () => {
17
17
  // Set the test data first
18
18
  Utils.setAccessToken(id, testAccessToken);
19
- Utils.setEncryptedPrivateKey(id, privateKey, hashKey);
19
+ Utils.setEncryptedPrivateKey(id, privateKey, password);
20
20
  Utils.setWallabyAuthPubKey(id, wallabyAuthPublicKey);
21
- Utils.setEncryptedSeedPhrase(id, publicKey, seedPhrase, SeedPhraseType.Standard);
21
+ Utils.setEncryptedSeedPhrase(id, publicKey, seedPhrase, SeedPhraseType.Standard, password, salt);
22
22
  // Clear local storage
23
- wallaby.wallet.clearWalletData({ userId: id });
23
+ wallaby.wallet.clearDevice();
24
24
  // Fetch Items from local storage after clearing
25
- const decryptedPrivateKey = Utils.getDecryptedPrivateKey(id, hashKey);
26
- const standardSeedphrase = await Utils.getDecryptedSeedPhrase(id, hashKey, SeedPhraseType.Standard);
25
+ const decryptedPrivateKey = Utils.getDecryptedPrivateKey(id, password);
26
+ const standardSeedphrase = await Utils.getDecryptedSeedPhrase({
27
+ userId: id,
28
+ password,
29
+ salt,
30
+ seedPhraseType: SeedPhraseType.Standard,
31
+ });
27
32
  const wallabyPublicKey = Utils.getWallabyAuthPubKey(id);
28
33
  const accessToken = Utils.getAccessToken(id);
29
34
 
package/src/types/auth.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { User } from './common';
2
2
 
3
3
  export declare type SignatureMessageRequest = {
4
- hashKey: string;
4
+ password: string;
5
5
  userId: string;
6
6
  };
7
7
 
@@ -15,30 +15,24 @@ export declare type SignatureMessageResponse = {
15
15
  };
16
16
 
17
17
  export declare type SignInRequest = {
18
- hashKey: string;
19
- };
20
-
21
- export declare type SignInResponse = {
22
- accessToken: string;
23
- user: User;
24
- error?: any;
18
+ password: string;
25
19
  };
26
20
 
27
21
  export declare type SignUpRequest = {
28
- hashKey: string;
22
+ password: string;
29
23
  firstName: string;
30
24
  lastName: string;
31
25
  email: string;
32
26
  };
33
27
 
34
- export declare type SignUpResponse = {
28
+ export declare type AuthResponse = {
35
29
  accessToken: string;
36
30
  user: User;
37
31
  error?: any;
38
32
  };
39
33
 
40
34
  export declare type ClientAuthPubKeyRequest = {
41
- hashKey: string;
35
+ password: string;
42
36
  userId: string;
43
37
  message: string;
44
38
  clientAuthPubKey: string;
@@ -2,6 +2,11 @@ import { Merchant, MerchantAsset } from './merchants';
2
2
 
3
3
  export declare type UtilsResponse = string | undefined;
4
4
 
5
+ export declare type GetDecryptedSeedPhraseResponse = {
6
+ standardSeedPhrase: UtilsResponse;
7
+ algorandSeedPhrase: UtilsResponse;
8
+ };
9
+
5
10
  export declare type WallabyError = {
6
11
  statusCode: number;
7
12
  message: string;
@@ -186,7 +191,7 @@ export declare interface RequestOptions extends RequestInit {
186
191
  export declare type RequestRoute = {
187
192
  fullPath: string | ((params: any) => string);
188
193
  method: RequestMothod;
189
- accessTokenRequired: boolean;
194
+ requiresAccessToken: boolean;
190
195
  };
191
196
 
192
197
  export declare enum ApiKeyStatus {
@@ -89,7 +89,7 @@ export declare type TransferRequest = {
89
89
  assetId: string;
90
90
  reference: string;
91
91
  memo?: string;
92
- hashKey: string;
92
+ password: string;
93
93
  };
94
94
 
95
95
  export declare type TransferResponse = {
@@ -135,5 +135,5 @@ export declare type CreateAllowanceRequest = {
135
135
  contractAddress: string;
136
136
  reference: string;
137
137
  memo?: string;
138
- hashKey: string;
138
+ password: string;
139
139
  };
@@ -45,7 +45,7 @@ export declare type WalletAssetsResponse = {
45
45
 
46
46
  export declare type CreateWalletRequest = {
47
47
  userId?: string;
48
- hashKey: string;
48
+ password: string;
49
49
  firstName: string;
50
50
  lastName: string;
51
51
  email: string;
@@ -54,9 +54,17 @@ export declare type CreateWalletRequest = {
54
54
  signature: string;
55
55
  };
56
56
 
57
- export declare type ClearWalletInput = {
58
- userId: string;
59
- walletId?: string;
57
+ export declare type ImportWalletRequest = {
58
+ password: string;
59
+ seedPhrase: string;
60
+ };
61
+
62
+ export declare type ImportWalletResponse = {
63
+ wallabyAuthPubKey: string;
64
+ assets: Array<UserAsset>;
65
+ encryptedSeed: Encrypted;
66
+ wallet: Wallet;
67
+ error?: any;
60
68
  };
61
69
 
62
70
  export declare type Wallet = {
@@ -91,7 +99,7 @@ export declare type CreateWalletResponse = {
91
99
  export declare type ConvertMnemonicSeedPhraseRequest = {
92
100
  reference: string;
93
101
  signature: string;
94
- hashKey: string;
102
+ password: string;
95
103
  message: string;
96
104
  clientAuthPubKey: string;
97
105
  encryptedSeedPhrase: Encrypted;
@@ -108,7 +116,7 @@ export declare type ConvertMnemonicSeedPhraseResponse = {
108
116
 
109
117
  export declare type RecoverWalletRequest = {
110
118
  clientAuthPubKey: string;
111
- newHashKey: string;
119
+ newPassword: string;
112
120
  seedPhrase: string;
113
121
  };
114
122