wallaby-cash 1.2.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.
Files changed (69) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +66 -0
  3. package/dist/base.d.ts +10 -0
  4. package/dist/helpers/logger.d.ts +2 -0
  5. package/dist/index.d.ts +45 -0
  6. package/dist/index.esm.js +2 -0
  7. package/dist/index.esm.js.map +1 -0
  8. package/dist/index.js +2 -0
  9. package/dist/index.js.map +1 -0
  10. package/dist/index.umd.js +2 -0
  11. package/dist/index.umd.js.map +1 -0
  12. package/dist/lib/auth/index.d.ts +54 -0
  13. package/dist/lib/index.d.ts +3 -0
  14. package/dist/lib/system/index.d.ts +32 -0
  15. package/dist/lib/transactions/index.d.ts +80 -0
  16. package/dist/lib/utils/index.d.ts +21 -0
  17. package/dist/lib/utils/utils.d.ts +68 -0
  18. package/dist/lib/wallet/index.d.ts +99 -0
  19. package/dist/localStorageMock.d.ts +7 -0
  20. package/dist/routes/auth.d.ts +33 -0
  21. package/dist/routes/index.d.ts +3 -0
  22. package/dist/routes/system.d.ts +23 -0
  23. package/dist/routes/transactions.d.ts +28 -0
  24. package/dist/routes/wallet.d.ts +53 -0
  25. package/dist/tests/data/auth.d.ts +11 -0
  26. package/dist/tests/data/config.d.ts +6 -0
  27. package/dist/tests/data/index.d.ts +4 -0
  28. package/dist/tests/data/system.d.ts +47 -0
  29. package/dist/tests/data/user.d.ts +20 -0
  30. package/dist/types/auth.d.ts +48 -0
  31. package/dist/types/common.d.ts +206 -0
  32. package/dist/types/index.d.ts +5 -0
  33. package/dist/types/merchants.d.ts +43 -0
  34. package/dist/types/transactions.d.ts +127 -0
  35. package/dist/types/wallet.d.ts +123 -0
  36. package/package.json +90 -0
  37. package/src/base.ts +95 -0
  38. package/src/helpers/logger.ts +11 -0
  39. package/src/index.ts +58 -0
  40. package/src/lib/auth/index.ts +225 -0
  41. package/src/lib/index.ts +3 -0
  42. package/src/lib/system/index.ts +104 -0
  43. package/src/lib/transactions/index.ts +259 -0
  44. package/src/lib/utils/index.ts +80 -0
  45. package/src/lib/utils/utils.ts +224 -0
  46. package/src/lib/wallet/index.ts +515 -0
  47. package/src/localStorageMock.js +23 -0
  48. package/src/routes/auth.ts +34 -0
  49. package/src/routes/index.ts +3 -0
  50. package/src/routes/system.ts +24 -0
  51. package/src/routes/transactions.ts +29 -0
  52. package/src/routes/wallet.ts +65 -0
  53. package/src/tests/__mocks__/axios.js +4 -0
  54. package/src/tests/__mocks__/localStorageMock.js +23 -0
  55. package/src/tests/auth.spec.ts +117 -0
  56. package/src/tests/data/auth.ts +49 -0
  57. package/src/tests/data/config.ts +8 -0
  58. package/src/tests/data/index.ts +4 -0
  59. package/src/tests/data/system.ts +54 -0
  60. package/src/tests/data/user.ts +25 -0
  61. package/src/tests/system.spec.ts +47 -0
  62. package/src/tests/utils.spec.ts +70 -0
  63. package/src/tests/wallet.spec.ts +44 -0
  64. package/src/types/auth.ts +57 -0
  65. package/src/types/common.ts +230 -0
  66. package/src/types/index.ts +5 -0
  67. package/src/types/merchants.ts +47 -0
  68. package/src/types/transactions.ts +139 -0
  69. package/src/types/wallet.ts +141 -0
@@ -0,0 +1,23 @@
1
+ class LocalStorageMock {
2
+ constructor() {
3
+ this.store = {};
4
+ }
5
+
6
+ clear() {
7
+ this.store = {};
8
+ }
9
+
10
+ getItem(key) {
11
+ return this.store[key] || null;
12
+ }
13
+
14
+ setItem(key, value) {
15
+ this.store[key] = String(value);
16
+ }
17
+
18
+ removeItem(key) {
19
+ delete this.store[key];
20
+ }
21
+ }
22
+
23
+ global.localStorage = new LocalStorageMock();
@@ -0,0 +1,117 @@
1
+ import { config, testUser } from './data';
2
+ import { setEncryptedPrivateKey, getAccessToken } from '../lib/utils/utils';
3
+ import { SignUpResponse, SignatureMessageResponse, User } from '../types';
4
+ import Wallaby from '../index';
5
+ import mockAxios from 'axios';
6
+ import axios from 'axios';
7
+
8
+ describe('Auth Functions', () => {
9
+ const {
10
+ id,
11
+ hashKey,
12
+ firstName,
13
+ lastName,
14
+ email,
15
+ testAccessToken,
16
+ wallabyAuthPublicKey,
17
+ message,
18
+ hashedMessage,
19
+ signature,
20
+ publicKey,
21
+ privateKey,
22
+ wallabyUserId,
23
+ } = testUser;
24
+ const wallaby = new Wallaby(config);
25
+ const mockAxiosSpy = jest.spyOn(mockAxios, 'post');
26
+ afterEach(() => {
27
+ mockAxiosSpy.mockRestore()
28
+ })
29
+ describe('signatureMessage()', () => {
30
+ beforeEach(() => {
31
+ mockAxiosSpy.mockImplementationOnce(() => Promise.resolve({ data: { message } }))
32
+ })
33
+ afterAll(() => {
34
+ mockAxiosSpy.mockRestore()
35
+ })
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();
40
+ });
41
+ 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
+ expect(response?.clientAuthPubKey).not.toEqual(testUser.publicKey);
45
+ expect(response?.decryptedClientAuthPrivKey).not.toEqual(testUser.privateKey);
46
+ });
47
+ 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
+ expect(response?.decryptedClientAuthPrivKey).toEqual(testUser.privateKey);
51
+ expect(response?.clientAuthPubKey).toEqual(testUser.publicKey);
52
+ });
53
+ it('Returns all response properties', async () => {
54
+ const response = await wallaby.auth.signatureMessage({ hashKey, userId: id });
55
+ const { message, decryptedClientAuthPrivKey, clientAuthPubKey, hashedMessage, signature } =
56
+ response as SignatureMessageResponse;
57
+ expect(decryptedClientAuthPrivKey).toBeDefined();
58
+ expect(clientAuthPubKey).toBeDefined();
59
+ expect(message).toBeDefined();
60
+ expect(hashedMessage).toBeDefined();
61
+ expect(signature).toBeDefined();
62
+ });
63
+ });
64
+ describe('signUp()', () => {
65
+ beforeEach(() => {
66
+ const signatureMessageSpy = jest.spyOn(wallaby.auth, 'signatureMessage');
67
+ const signUpSpy = jest.spyOn(wallaby.auth, 'signUp');
68
+ signatureMessageSpy.mockImplementation(() => {
69
+ return Promise.resolve({
70
+ message: message,
71
+ hashedMessage: hashedMessage,
72
+ signature: signature,
73
+ clientAuthPubKey: publicKey,
74
+ decryptedClientAuthPrivKey: privateKey,
75
+ });
76
+ });
77
+ mockAxiosSpy.mockImplementationOnce(() => {
78
+ return Promise.resolve({
79
+ data: {
80
+ user: {
81
+ id: wallabyUserId,
82
+ firstName,
83
+ lastName,
84
+ externalUserId: id,
85
+ wallabyAuthPubKey: wallabyAuthPublicKey,
86
+ wallabyAuthPubKeyVersion: 1,
87
+ },
88
+ accessToken: testAccessToken,
89
+ },
90
+ });
91
+ })
92
+ // signUpSpy.mockImplementation(() => {
93
+ // return Promise.resolve({
94
+
95
+ // })
96
+ // })
97
+ });
98
+ it('Calls signatureMessage to get a new message', async () => {
99
+ await wallaby.auth.signUp({ hashKey, firstName, lastName, email });
100
+
101
+ expect(wallaby.auth.signatureMessage).toHaveBeenCalled();
102
+ });
103
+ 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
+ expect(accessToken).toEqual(testAccessToken);
107
+ expect(getAccessToken(id)).toBeDefined()
108
+ });
109
+ 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
+ expect(user.wallabyAuthPubKey).toEqual(wallabyAuthPublicKey);
113
+ expect(user.id).toBe(wallabyUserId)
114
+ });
115
+ });
116
+ });
117
+ 0;
@@ -0,0 +1,49 @@
1
+ import { testUser } from './user';
2
+ export const signatureMessageMockResponse = {
3
+ // message, hashedMessage, signature, decryptedClientAuthPrivKey, clientAuthPubKey
4
+ message: testUser.message,
5
+ hashedMessage: '',
6
+ signature: '',
7
+ decryptedClientAuthPrivKey: testUser.privateKey,
8
+ clientAuthPubKey: testUser.publicKey,
9
+ };
10
+
11
+ export const testClientJWTKeyPair = {
12
+ privateKey: `-----BEGIN RSA PRIVATE KEY-----
13
+ MIIEogIBAAKCAQBphoSqssjiSHIVCZVEgFFhdAaEQ6wUR0mUY87Zq8Ul7PD+mLC6
14
+ CHsP+Z0GiNVaGAEPYMyIjhTFcXWq1nzTFBHHw12tRTFbsEtc6yJ0gPeHHI70OKPj
15
+ kBTK82XgvzfyY7ypvEC5mHoTyEZwJF3eDi659USha1257isnZ8JB8kkK/UUhtd8t
16
+ NshCR5EI8mAT3Ps9iFfU6hp+3fgpnNZYonjAEyYYhIsg8wxk2MS12QtC0J7aVnbW
17
+ ehm2gRrWQsYhEnqckqiCerkufvFv73xCm9XkOuhKg7+IMrdkIuqj97DRkhL5tMDx
18
+ U7IzVqEAoND1BLnpc0rus3mVCfIK77o9EdgRAgMBAAECggEAUyfJy6nvW0GzhJh0
19
+ o/JqLt17dSbOp3w1o1WzXxxY0zYQAtDYEwEz2Lbe4pNZbRGVZETnaIRuIdjy3JkA
20
+ 7GTYTg7J9wybhKE8AhDYqe4nILWEgTdRDrYvbG65TY3hzISD202Zw6dAK+6acyx1
21
+ O9L5R1jbqEgvJ6FjKD4/ejAvFxTP0Ds9hhPOv8SK17E6n4ylyFcF2nF1PJ35yTP4
22
+ fw0REg2Ur/HveM50GWWHwOtOw0ZCXBYkLiZI3G9NCnCxKDEUZtGUp/d9s5rqG/Mv
23
+ Pe227cH2uqBtW9Al/T/Rt270Do111LuZXR7r+fSVqzWqNW4UTl8K8BVVZiEcQwr8
24
+ OtimcQKBgQDA89/hs2noJyZ0PvPXy0bcT6ZAiSHOffiiC0hImAFZKN70/9B5GK/T
25
+ Iv0r1L9lYIH7NINDE5ihvCUEmV49ZRiyrb4ItNpITn23pfey8flsM+WV2GhZeLuw
26
+ /caXthrpLwJ+CMo0u+k4MEWnfuzd7g4jFZ5v7ItmcpvwGRuNQrBjnwKBgQCMAYZf
27
+ LpDpSdkGSHUNkFkGI6chnoIqqYmPbPWrBgUTddHzNKDM6vyhnPCW4mTHLq4GHz/g
28
+ 4Ohz+qLx7I+IgwS5HzOBCtC72XBLQ1lOBMR+NqTjvibb/xltep2urWDWUfPKd0ip
29
+ O71aOSeKc2PvpB50bG5v5s/zlzlue47ma7amTwKBgGeqHpxaEgpCDmzh7YwAkH+I
30
+ 419Ezb7s+wnEWf92ezL1vGOQlOaalswuviowUOwcX3khC2ycOKKcPJ8t7u25RP2q
31
+ TrDKyYOTeAOUzXF8g27Yqv5ImDeJn/1FOs8DbY3eTc581nZihrhDZwjILmZFoZ7D
32
+ 3K1xPqu544GpW54XOEEtAoGADlHNm4iYu7OY5eKdTkDYSh91ZaPfrltevXOogNCB
33
+ zma7jYNxeuQB6Mmzdcs8AX9Nv0SM9QQr4kjdR58pYw37eq+tReKETOJFcP03chpc
34
+ uof+P2jgcpnZ0O+8lvQWtnT1WVzv6pc4m7TCzY9Vxlnj34aDmSBjXoe2EQ3EJN8Z
35
+ dFMCgYEAlpTm8UaXItdgT462lqSfzVb0mS8RGSvTCG/6exIfxionXQC8XChCzDcj
36
+ wbfIhLmc1na44ek7giRNZrRgsEOkj+q9BZw1MMijd4yq/8yFjiR5G/PMUWPz7sa6
37
+ uUWlaWmuXpTqhmQVBd8YJPIVd5zbQ3KMgxl6EXEiHmdEri0JnCM=
38
+ -----END RSA PRIVATE KEY-----`,
39
+
40
+ publicKey: `-----BEGIN PUBLIC KEY-----
41
+ MIIBITANBgkqhkiG9w0BAQEFAAOCAQ4AMIIBCQKCAQBphoSqssjiSHIVCZVEgFFh
42
+ dAaEQ6wUR0mUY87Zq8Ul7PD+mLC6CHsP+Z0GiNVaGAEPYMyIjhTFcXWq1nzTFBHH
43
+ w12tRTFbsEtc6yJ0gPeHHI70OKPjkBTK82XgvzfyY7ypvEC5mHoTyEZwJF3eDi65
44
+ 9USha1257isnZ8JB8kkK/UUhtd8tNshCR5EI8mAT3Ps9iFfU6hp+3fgpnNZYonjA
45
+ EyYYhIsg8wxk2MS12QtC0J7aVnbWehm2gRrWQsYhEnqckqiCerkufvFv73xCm9Xk
46
+ OuhKg7+IMrdkIuqj97DRkhL5tMDxU7IzVqEAoND1BLnpc0rus3mVCfIK77o9EdgR
47
+ AgMBAAE=
48
+ -----END PUBLIC KEY-----`,
49
+ };
@@ -0,0 +1,8 @@
1
+ import { testUser } from './user';
2
+
3
+ export const config = {
4
+ apiKey: 'cd130760744347298da13eb6e14fb162',
5
+ baseUrl: 'https://dev-testnet.wallaby.cash/api/v1',
6
+ userId: testUser.id,
7
+ jwt: 'eyJhbGciOiJSUzI1NiJ9.eyJleHRlcm5hbFVzZXJJZCI6ImFlZTFjMzczLWQ0NmItNGJmYS04Nzk4LWVjOWI4ZmU1MWJkZiIsImV4cGlyYXRpb24iOiIyMDIzLTA0LTI2VDE3OjEyOjE4LTA1OjAwIiwiaGFzaF9zdHJpbmciOiI2YThjZjBmMWY3ODIwMmIyOTI0MTYyMDJkOWMwYjdmODNhNzY3MDliOWM1ZTg5NzU0OTQ1ZDk2MzU3MTdjZmQ3In0.WdBsgkPrLS_zXuZLfCBznvbuDjjs-7A3Ck3ayJ5CrPBX-lMPMRRvpWHtONFQ9V0nEDWg_KLNaw1nD5ljG1n4nFXxucxND4EUEz3WZa3DXUSGFbQPSxRQsY6Gx-MM-ERbJXODsEyRPdBbtOFtYvil3uAEkuGgLKguSInFpy3nr4k',
8
+ };
@@ -0,0 +1,4 @@
1
+ export * from './auth';
2
+ export * from './config';
3
+ export * from './user';
4
+ export * from './system';
@@ -0,0 +1,54 @@
1
+ export const mockBlockchainsResponse = {
2
+ chains: [
3
+ {
4
+ id: '6e464058-67c1-4273-a6a4-8aae522e34be',
5
+ name: 'ALGORAND',
6
+ derivationPath: "m/84'/0'/0'/0/0",
7
+ addressRegex: '/^0x[a-fA-F0-9]{40}$/',
8
+ slip44: 1,
9
+ indexUrl: 'string',
10
+ rpcUrl: 'https://testnet-algorand.api.purestake.io/ps2',
11
+ chainId: '1',
12
+ },
13
+ ],
14
+ };
15
+
16
+ export const mockTokensResponse = {
17
+ assets: [
18
+ {
19
+ chainId: '6e464058-67c1-4273-a6a4-8aae522e34be',
20
+ chainName: 'ALGORAND',
21
+ name: 'ALGORAND',
22
+ symbol: 'ALGO',
23
+ type: 'COIN',
24
+ tokenStandard: 'ALGO_STANDARD',
25
+ assetIndex: 1,
26
+ description: 'string',
27
+ ownershipType: 'SINGLE',
28
+ multisigVersion: 0,
29
+ multisigSignerThreshold: 0,
30
+ chain: {
31
+ id: '6e464058-67c1-4273-a6a4-8aae522e34be',
32
+ name: 'ALGORAND',
33
+ derivationPath: "m/84'/0'/0'/0/0",
34
+ addressRegex: '/^0x[a-fA-F0-9]{40}$/',
35
+ slip44: 1,
36
+ indexUrl: 'string',
37
+ rpcUrl: 'https://testnet-algorand.api.purestake.io/ps2',
38
+ chainId: '1',
39
+ },
40
+ },
41
+ ],
42
+ };
43
+
44
+ export const mockUserData = {
45
+ user: {
46
+ id: 'string',
47
+ externalUserId: 'aee1c373-d46b-4bfa-8798-ec9b8fe51bdf',
48
+ firstName: 'Joanna',
49
+ lastName: 'Smith',
50
+ latestWallabyAuthPubKey:
51
+ '4ecb720b1392468c75803d6252ac987c113206955070b96df1208c1c480338168e1407cec4b5af2f91d12af9b725cbd85af994b29c6364971a7ef8d955be83dc',
52
+ latestWallabyAuthPubKeyVersion: '1',
53
+ },
54
+ };
@@ -0,0 +1,25 @@
1
+ export const testUser = {
2
+ id: 'aee1c373-d46b-4bfa-8798-ec9b8fe51bdf',
3
+ wallabyUserId: 'aee1c373-d46b-4bfa-8798-ec9b8fe51bdf',
4
+ wrongId: 'aee1c373-b46d-4dfa-8798-ec9d8fe51dbg',
5
+ algoAddress: 'FNQUYN4Z3JEASHEEU73RMMFHBSR2VPG25ECK4ITBPOXPJBKEFZYEFOTOYU',
6
+ firstName: 'Joanna',
7
+ lastName: 'Smith',
8
+ email: 'joanna.smith@yopmail.com',
9
+ hashKey: '16charencryption',
10
+ wrongHashKey: '17charencryption!',
11
+ message: 'c25d687f94ab48bfa87baeef4a2741ab',
12
+ hashedMessage: '0x721edfb991965324620d2259fd1e0e1f19f36eb46d9cd8ada68686bc3f7cc5d1',
13
+ signature: '0x9b765cea1d8fec0c1c4f51567dfcd5554fc0fad82074049f10ad5d6d1db46d253155f7793d9f88d55ff3fce28c0112528fde02962eab9e04089715e048ae9ce51b',
14
+ wallabyAuthPublicKey:
15
+ '4ecb720b1392468c75803d6252ac987c113206955070b96df1208c1c480338168e1407cec4b5af2f91d12af9b725cbd85af994b29c6364971a7ef8d955be83dc',
16
+ privateKey: '0xb3a4611225c37c6f1cb5414532c87be388f512c00cbcec6cfc5a4c283742796d',
17
+ encryptedPrivateKey:
18
+ 'U2FsdGVkX18n+RmJbtT89D0sxi1UbVgYtY5uZrHFacvuoYCVJbE0e49scogCVmtDwitNHkBz6HDIGA0/TxP2eHvA9Of+/EhHSfCFTtPwOvBN44EgXgAtRpx3xzCDukHE',
19
+ publicKey:
20
+ 'e3421d7f9d6888ea83bef6b28ce0a2ab6eb6fe8a8fbfa3743240992590816b08f9a62edcc63296d056c552054d583fec36d23ef11dffb24c95aaf4a47d50dccc',
21
+ seedPhrase:
22
+ 'upset zoo adult butter oxygen grow liberty suit also tape river crack rich limb art guitar crime aware crowd blouse script boss mask west',
23
+ testAccessToken:
24
+ 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyIjp7ImlkIjoiMGViYWY1ZWYtZGU5Yy00YjgxLWFjYjMtYTUxYzY5MzQyNTgyIn0sInN1YiI6IjBlYmFmNWVmLWRlOWMtNGI4MS1hY2IzLWE1MWM2OTM0MjU4MiIsImlhdCI6MTY3NDIwNjk2MX0.yjzPKFMUkjc-OMHhRPBX5n4uBgkDN0Am7AGmJWYAc_8',
25
+ };
@@ -0,0 +1,47 @@
1
+ import { config, mockBlockchainsResponse, mockTokensResponse, mockUserData, testUser } from './data';
2
+ import Wallaby from '../index';
3
+ import mockAxios from 'axios';
4
+
5
+ const wallaby = new Wallaby(config);
6
+
7
+ describe('System Functions', () => {
8
+ const mockAxiosSpy = jest.spyOn(mockAxios, 'get');
9
+ describe('getSupportedBlockchains()', () => {
10
+ it('Returns an array of supported blockchains', async () => {
11
+ mockAxiosSpy.mockImplementationOnce(() => Promise.resolve({ data: mockBlockchainsResponse }));
12
+ const response = await wallaby.system.getSupportedBlockchains();
13
+ expect(response).toBeInstanceOf(Array);
14
+ });
15
+ });
16
+ describe('getSupportedTokens()', () => {
17
+ it('Returns an array of supported tokens', async () => {
18
+ mockAxiosSpy.mockImplementationOnce(() => Promise.resolve({ data: mockTokensResponse }));
19
+ const response = await wallaby.system.getSupportedTokens();
20
+ expect(response).toBeInstanceOf(Array);
21
+ });
22
+ });
23
+ describe('getUserData()', () => {
24
+ it('Returns user data object', async () => {
25
+ mockAxiosSpy.mockImplementation(() => Promise.resolve({ data: mockUserData }));
26
+ const response = await wallaby.system.getUserData(testUser.id);
27
+ expect(response?.externalUserId).toBe(testUser.id);
28
+ expect(response?.firstName).toBe(testUser.firstName);
29
+ });
30
+ xit('Returns `User not found` error with wrong ID', async () => {
31
+ mockAxiosSpy.mockImplementation(() => Promise.reject({ message: 'User not found' }));
32
+ const response = await wallaby.system.getUserData(testUser.wrongId);
33
+ });
34
+ });
35
+ describe('getUserByExternalUserId()', () => {
36
+ it('Returns user data object', async () => {
37
+ mockAxiosSpy.mockImplementation(() => Promise.resolve({ data: mockUserData }));
38
+ const response = await wallaby.system.getUserData(testUser.id);
39
+ expect(response?.externalUserId).toBe(testUser.id);
40
+ expect(response?.firstName).toBe(testUser.firstName);
41
+ });
42
+ xit('Returns `User not found` error with wrong ID', async () => {
43
+ mockAxiosSpy.mockImplementation(() => Promise.reject({ message: 'User not found' }));
44
+ const response = await wallaby.system.getUserData(testUser.wrongId);
45
+ });
46
+ });
47
+ });
@@ -0,0 +1,70 @@
1
+ jest.mock('../lib/utils');
2
+ // import { Utils } from '../lib/utils';
3
+
4
+ import {
5
+ setWallabyAuthPubKey,
6
+ getWallabyAuthPubKey,
7
+ setEncryptedPrivateKey,
8
+ getEncryptedPrivateKey,
9
+ getDecryptedPrivateKey,
10
+ setEncryptedSeedPhrase,
11
+ getEncryptedSeedPhrase,
12
+ validatePassword,
13
+ } from '../lib/utils/utils';
14
+ import { SeedPhraseType } from '../types';
15
+ 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
+
22
+ describe('Utilities functions', () => {
23
+ const { id, hashKey, wrongHashKey, seedPhrase, privateKey, publicKey } = testUser;
24
+
25
+ describe('WallabyAuthPublicKey', () => {
26
+ const setterResult = setWallabyAuthPubKey(id, publicKey);
27
+ const getterResult = getWallabyAuthPubKey(id);
28
+ it('stores key to local storage and returns true', () => {
29
+ expect(setterResult).toBeTruthy();
30
+ });
31
+ it('stores wallaby auth public key in local storage', () => {
32
+ expect(getterResult).toBeDefined();
33
+ });
34
+ });
35
+
36
+ describe('ClientAuthPrivateKey', () => {
37
+ const setterResult = setEncryptedPrivateKey(id, privateKey, hashKey);
38
+ const getterResult = getEncryptedPrivateKey(id);
39
+ it('stores key to local storage and returns true', () => {
40
+ expect(setterResult).toBeTruthy();
41
+ });
42
+ it('encrypts key before storing it', () => {
43
+ expect(privateKey).not.toEqual(getterResult);
44
+ });
45
+ it('stores client auth private key in local storage', () => {
46
+ expect(getterResult).toBeDefined();
47
+ });
48
+ it('decrypts private key if hashKey is correct', () => {
49
+ const decryptedResult = getDecryptedPrivateKey(id, hashKey);
50
+ expect(decryptedResult).toBeDefined();
51
+ expect(decryptedResult).toEqual(privateKey);
52
+ });
53
+ it('returns an error if hashKey is incorrect', () => {
54
+ localStorage.removeItem(`${process.env.NODE_ENV}-client-auth-private-key-${id}`);
55
+ const decryptedResult = getDecryptedPrivateKey(id, wrongHashKey);
56
+ expect(decryptedResult).toBeUndefined();
57
+ });
58
+ });
59
+
60
+ describe('EncryptedSeedPhrase storing and fetching', () => {
61
+ it('stores seedPhrase in local storage', async () => {
62
+ const seedPhraseIsSet = await setEncryptedSeedPhrase(id, publicKey, seedPhrase, SeedPhraseType.Standard);
63
+ expect(seedPhraseIsSet).toBeTruthy();
64
+ });
65
+ it('encrypts seedPhrase before storing it', async () => {
66
+ const seedPhraseIsFound = await getEncryptedSeedPhrase(id, SeedPhraseType.Standard);
67
+ expect(seedPhrase).not.toEqual(seedPhraseIsFound);
68
+ });
69
+ });
70
+ });
@@ -0,0 +1,44 @@
1
+ import Wallaby from '../index';
2
+ import * as Utils from '../lib/utils/utils';
3
+ import { SeedPhraseType } from '../types';
4
+ import { config, testUser } from './data';
5
+ const wallaby = new Wallaby(config);
6
+
7
+ const { id, hashKey, testAccessToken, privateKey, seedPhrase, wallabyAuthPublicKey, publicKey } = testUser;
8
+
9
+ describe('Wallet Functions', () => {
10
+ describe('getTokenBalance()', () => {
11
+ it('success', () => {
12
+ expect(true).toBeTruthy();
13
+ });
14
+ });
15
+ describe('clearWalletData()', () => {
16
+ it('clears wallet data from local storage', async () => {
17
+ // Set the test data first
18
+ Utils.setAccessToken(id, testAccessToken);
19
+ Utils.setEncryptedPrivateKey(id, privateKey, hashKey);
20
+ Utils.setWallabyAuthPubKey(id, wallabyAuthPublicKey);
21
+ Utils.setEncryptedSeedPhrase(id, publicKey, seedPhrase, SeedPhraseType.Standard);
22
+ // Clear local storage
23
+ wallaby.wallet.clearWalletData({ userId: id });
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);
27
+ const wallabyPublicKey = Utils.getWallabyAuthPubKey(id);
28
+ const accessToken = Utils.getAccessToken(id);
29
+
30
+ expect(decryptedPrivateKey).toBeUndefined();
31
+ expect(standardSeedphrase).toBeUndefined();
32
+ expect(wallabyPublicKey).toBeUndefined();
33
+ expect(accessToken).toBeUndefined();
34
+ });
35
+ });
36
+ // describe('create()', () => {});
37
+ // describe('convertMnemonicSeedphrase()', () => {});
38
+ // describe('recover()', () => {});
39
+ // describe('getUserAssets()', () => {});
40
+ // describe('getUserWallets()', () => {});
41
+ // describe('getWalletAssets()', () => {});
42
+ // describe('createMultisigAsset()', () => {});
43
+ // describe('initRecoveryFlow()', () => {});
44
+ });
@@ -0,0 +1,57 @@
1
+ import { User } from './common';
2
+
3
+ export declare type SignatureMessageRequest = {
4
+ hashKey: string;
5
+ userId: string;
6
+ };
7
+
8
+ export declare type SignatureMessageResponse = {
9
+ message: string;
10
+ hashedMessage: string;
11
+ signature: string;
12
+ clientAuthPubKey: string;
13
+ decryptedClientAuthPrivKey: string;
14
+ error?: any;
15
+ };
16
+
17
+ export declare type SignInRequest = {
18
+ hashKey: string;
19
+ };
20
+
21
+ export declare type SignInResponse = {
22
+ accessToken: string;
23
+ user: User;
24
+ error?: any;
25
+ };
26
+
27
+ export declare type SignUpRequest = {
28
+ hashKey: string;
29
+ firstName: string;
30
+ lastName: string;
31
+ email: string;
32
+ };
33
+
34
+ export declare type SignUpResponse = {
35
+ accessToken: string;
36
+ user: User;
37
+ error?: any;
38
+ };
39
+
40
+ export declare type ClientAuthPubKeyRequest = {
41
+ hashKey: string;
42
+ userId: string;
43
+ message: string;
44
+ clientAuthPubKey: string;
45
+ signature: string;
46
+ newClientAuthPubKey: string;
47
+ };
48
+
49
+ export declare type ClientAuthPubKeyResponse = {
50
+ user: User;
51
+ error?: any;
52
+ };
53
+
54
+ export declare type RefreshAccessTokenResponse = {
55
+ accessToken: string;
56
+ error?: any;
57
+ };