@rosen-bridge/address-codec 0.1.0 → 0.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 (50) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/dist/const.d.ts +1 -0
  3. package/dist/const.d.ts.map +1 -1
  4. package/dist/const.js +2 -1
  5. package/dist/decoder.d.ts +5 -2
  6. package/dist/decoder.d.ts.map +1 -1
  7. package/dist/decoder.js +7 -2
  8. package/dist/encoder.d.ts +1 -1
  9. package/dist/encoder.d.ts.map +1 -1
  10. package/dist/encoder.js +8 -2
  11. package/dist/index.d.ts +1 -1
  12. package/dist/index.js +1 -1
  13. package/dist/lib/const.d.ts +5 -0
  14. package/dist/lib/const.d.ts.map +1 -0
  15. package/dist/lib/const.js +5 -0
  16. package/dist/lib/decoder.d.ts +8 -0
  17. package/dist/lib/decoder.d.ts.map +1 -0
  18. package/dist/lib/decoder.js +31 -0
  19. package/dist/lib/encoder.d.ts +8 -0
  20. package/dist/lib/encoder.d.ts.map +1 -0
  21. package/dist/lib/encoder.js +37 -0
  22. package/dist/lib/index.d.ts +4 -0
  23. package/dist/lib/index.d.ts.map +1 -0
  24. package/dist/lib/index.js +4 -0
  25. package/dist/lib/types.d.ts +7 -0
  26. package/dist/lib/types.d.ts.map +1 -0
  27. package/dist/lib/types.js +11 -0
  28. package/dist/tests/decoder.spec.d.ts +2 -0
  29. package/dist/tests/decoder.spec.d.ts.map +1 -0
  30. package/dist/tests/decoder.spec.js +84 -0
  31. package/dist/tests/encoder.spec.d.ts +2 -0
  32. package/dist/tests/encoder.spec.d.ts.map +1 -0
  33. package/dist/tests/encoder.spec.js +98 -0
  34. package/dist/tests/testData.d.ts +12 -0
  35. package/dist/tests/testData.d.ts.map +1 -0
  36. package/dist/tests/testData.js +12 -0
  37. package/dist/tsconfig.tsbuildinfo +1 -0
  38. package/dist/types.d.ts +3 -3
  39. package/dist/types.js +11 -7
  40. package/dist/vitest.config.d.ts +3 -0
  41. package/dist/vitest.config.d.ts.map +1 -0
  42. package/dist/vitest.config.js +18 -0
  43. package/lib/const.ts +1 -0
  44. package/lib/decoder.ts +11 -1
  45. package/lib/encoder.ts +12 -1
  46. package/package.json +1 -1
  47. package/tests/decoder.spec.ts +20 -1
  48. package/tests/encoder.spec.ts +35 -1
  49. package/tests/testData.ts +7 -0
  50. package/tsconfig.build.tsbuildinfo +1 -1
@@ -4,7 +4,12 @@ import {
4
4
  UnsupportedChainError,
5
5
  decodeAddress,
6
6
  } from '../lib';
7
- import { BITCOIN_CHAIN, CARDANO_CHAIN, ERGO_CHAIN } from '../lib/const';
7
+ import {
8
+ BITCOIN_CHAIN,
9
+ CARDANO_CHAIN,
10
+ ERGO_CHAIN,
11
+ ETHEREUM_CHAIN,
12
+ } from '../lib/const';
8
13
 
9
14
  describe('decodeAddress', () => {
10
15
  /**
@@ -49,6 +54,20 @@ describe('decodeAddress', () => {
49
54
  expect(res).toEqual(testData.bitcoinAddress);
50
55
  });
51
56
 
57
+ /**
58
+ * @target `decodeAddress` should decode Ethereum address successfully
59
+ * @dependencies
60
+ * @scenario
61
+ * - run test
62
+ * - check returned value
63
+ * @expected
64
+ * - it should be address in hex format
65
+ */
66
+ it('should decode Ethereum address successfully', () => {
67
+ const res = decodeAddress(ETHEREUM_CHAIN, testData.encodedEthereumAddress);
68
+ expect(res).toEqual(testData.ethereumAddress);
69
+ });
70
+
52
71
  /**
53
72
  * @target `decodeAddress` should throw error when encoded address is more than 60 bytes
54
73
  * @dependencies
@@ -4,7 +4,12 @@ import {
4
4
  UnsupportedChainError,
5
5
  encodeAddress,
6
6
  } from '../lib';
7
- import { BITCOIN_CHAIN, CARDANO_CHAIN, ERGO_CHAIN } from '../lib/const';
7
+ import {
8
+ BITCOIN_CHAIN,
9
+ CARDANO_CHAIN,
10
+ ERGO_CHAIN,
11
+ ETHEREUM_CHAIN,
12
+ } from '../lib/const';
8
13
 
9
14
  describe('encodeAddress', () => {
10
15
  /**
@@ -49,6 +54,35 @@ describe('encodeAddress', () => {
49
54
  expect(res).toEqual(testData.encodedBitcoinAddress);
50
55
  });
51
56
 
57
+ /**
58
+ * @target `encodeAddress` should encode Ethereum address successfully
59
+ * @dependencies
60
+ * @scenario
61
+ * - run test
62
+ * - check returned value
63
+ * @expected
64
+ * - it should be output script of given address in hex
65
+ */
66
+ it('should encode Ethereum address successfully', () => {
67
+ const res = encodeAddress(ETHEREUM_CHAIN, testData.ethereumAddress);
68
+ expect(res).toEqual(testData.encodedEthereumAddress);
69
+ });
70
+
71
+ /**
72
+ * @target `encodeAddress` should throw error when address is not 40 bytes
73
+ * @dependencies
74
+ * @scenario
75
+ * - run test
76
+ * - run test & check thrown exception
77
+ * @expected
78
+ * - it should throw UnsupportedAddress error
79
+ */
80
+ it('should encode Ethereum address successfully', () => {
81
+ expect(() => {
82
+ encodeAddress(ETHEREUM_CHAIN, testData.invalidEthereumAddressLength);
83
+ }).toThrow(UnsupportedAddressError);
84
+ });
85
+
52
86
  /**
53
87
  * @target `encodeAddress` should throw error when encoded address is more than 60 bytes
54
88
  * @dependencies
package/tests/testData.ts CHANGED
@@ -16,3 +16,10 @@ export const longErgoAddress =
16
16
  'nB3L2PD3LBtiNhDYK7XhZ8nVt6uekBXN7RcPUKgdKLXFcrJiSPxmQsUKuUkTRQ1hbvDrxEQAKYurGFbaGD1RPxU7XqQimD78j23HHMQKL1boUGsnNhCxaVNAYMcFbQNo355Af8cWkhAN6';
17
17
  export const longEncodedAddress =
18
18
  '100304000e20a6ac381e6fa99929fd1477b3ba9499790a775e91d4c14c5aa86e9a118dfac8530400d801d601b2db6501fe730000ea02d1aedb63087201d901024d0e938c720201730198b2e4c672010510730200ade4c67201041ad901020ecdee7202';
19
+
20
+ export const ethereumAddress = '0xb416c8a6d7ec94706a9ae2c26c11d320519482b1';
21
+ export const encodedEthereumAddress =
22
+ 'b416c8a6d7ec94706a9ae2c26c11d320519482b1';
23
+
24
+ export const invalidEthereumAddressLength =
25
+ '0xb416c8a7ec94706a9ae2c26c11d320519482b1';