ripple-binary-codec 1.7.1 → 1.9.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 (99) hide show
  1. package/dist/enums/definitions.json +250 -1
  2. package/dist/enums/src/enums/definitions.json +250 -1
  3. package/dist/types/index.js +2 -0
  4. package/dist/types/index.js.map +1 -1
  5. package/dist/types/issue.d.ts +39 -0
  6. package/dist/types/issue.js +81 -0
  7. package/dist/types/issue.js.map +1 -0
  8. package/dist/types/xchain-bridge.d.ts +45 -0
  9. package/dist/types/xchain-bridge.js +102 -0
  10. package/dist/types/xchain-bridge.js.map +1 -0
  11. package/package.json +3 -4
  12. package/src/README.md +3 -0
  13. package/src/binary.ts +188 -0
  14. package/src/coretypes.ts +31 -0
  15. package/src/enums/README.md +144 -0
  16. package/src/enums/bytes.ts +75 -0
  17. package/src/enums/constants.ts +4 -0
  18. package/src/enums/definitions.json +2599 -0
  19. package/src/enums/field.ts +85 -0
  20. package/src/enums/index.ts +34 -0
  21. package/src/enums/utils-renumber.ts +134 -0
  22. package/src/enums/xrpl-definitions-base.ts +111 -0
  23. package/src/enums/xrpl-definitions.ts +32 -0
  24. package/src/hash-prefixes.ts +40 -0
  25. package/src/hashes.ts +76 -0
  26. package/src/index.ts +141 -0
  27. package/src/ledger-hashes.ts +187 -0
  28. package/src/quality.ts +39 -0
  29. package/src/serdes/binary-parser.ts +217 -0
  30. package/src/serdes/binary-serializer.ts +166 -0
  31. package/src/shamap.ts +186 -0
  32. package/src/types/account-id.ts +86 -0
  33. package/src/types/amount.ts +256 -0
  34. package/src/types/blob.ts +43 -0
  35. package/src/types/currency.ts +140 -0
  36. package/src/types/hash-128.ts +33 -0
  37. package/src/types/hash-160.ts +20 -0
  38. package/src/types/hash-256.ts +16 -0
  39. package/src/types/hash.ts +81 -0
  40. package/src/types/index.ts +61 -0
  41. package/src/types/issue.ts +96 -0
  42. package/src/types/path-set.ts +290 -0
  43. package/src/types/serialized-type.ts +120 -0
  44. package/src/types/st-array.ts +107 -0
  45. package/src/types/st-object.ts +192 -0
  46. package/src/types/uint-16.ts +49 -0
  47. package/src/types/uint-32.ts +56 -0
  48. package/src/types/uint-64.ts +105 -0
  49. package/src/types/uint-8.ts +49 -0
  50. package/src/types/uint.ts +57 -0
  51. package/src/types/vector-256.ts +84 -0
  52. package/test/amount.test.js +0 -43
  53. package/test/binary-json.test.js +0 -45
  54. package/test/binary-parser.test.js +0 -396
  55. package/test/binary-serializer.test.js +0 -289
  56. package/test/definitions.test.js +0 -160
  57. package/test/fixtures/account-tx-transactions.db +0 -0
  58. package/test/fixtures/codec-fixtures.json +0 -4466
  59. package/test/fixtures/data-driven-tests.json +0 -2919
  60. package/test/fixtures/delivermin-tx-binary.json +0 -1
  61. package/test/fixtures/delivermin-tx.json +0 -98
  62. package/test/fixtures/deposit-preauth-tx-binary.json +0 -1
  63. package/test/fixtures/deposit-preauth-tx-meta-binary.json +0 -1
  64. package/test/fixtures/deposit-preauth-tx.json +0 -58
  65. package/test/fixtures/escrow-cancel-binary.json +0 -1
  66. package/test/fixtures/escrow-cancel-tx.json +0 -6
  67. package/test/fixtures/escrow-create-binary.json +0 -1
  68. package/test/fixtures/escrow-create-tx.json +0 -10
  69. package/test/fixtures/escrow-finish-binary.json +0 -1
  70. package/test/fixtures/escrow-finish-meta-binary.json +0 -1
  71. package/test/fixtures/escrow-finish-tx.json +0 -95
  72. package/test/fixtures/ledger-full-38129.json +0 -1
  73. package/test/fixtures/ledger-full-40000.json +0 -1
  74. package/test/fixtures/negative-unl.json +0 -12
  75. package/test/fixtures/nf-token.json +0 -547
  76. package/test/fixtures/payment-channel-claim-binary.json +0 -1
  77. package/test/fixtures/payment-channel-claim-tx.json +0 -8
  78. package/test/fixtures/payment-channel-create-binary.json +0 -1
  79. package/test/fixtures/payment-channel-create-tx.json +0 -11
  80. package/test/fixtures/payment-channel-fund-binary.json +0 -1
  81. package/test/fixtures/payment-channel-fund-tx.json +0 -7
  82. package/test/fixtures/signerlistset-tx-binary.json +0 -1
  83. package/test/fixtures/signerlistset-tx-meta-binary.json +0 -1
  84. package/test/fixtures/signerlistset-tx.json +0 -94
  85. package/test/fixtures/ticket-create-binary.json +0 -1
  86. package/test/fixtures/ticket-create-tx.json +0 -7
  87. package/test/fixtures/x-codec-fixtures.json +0 -188
  88. package/test/hash.test.js +0 -135
  89. package/test/ledger.test.js +0 -29
  90. package/test/lower-case-hex.test.js +0 -46
  91. package/test/pseudo-transaction.test.js +0 -38
  92. package/test/quality.test.js +0 -15
  93. package/test/shamap.test.js +0 -89
  94. package/test/signing-data-encoding.test.js +0 -242
  95. package/test/tx-encode-decode.test.js +0 -119
  96. package/test/types.test.js +0 -34
  97. package/test/uint.test.js +0 -148
  98. package/test/utils.js +0 -30
  99. package/test/x-address.test.js +0 -181
@@ -1,94 +0,0 @@
1
- {
2
- "Account": "rfCp6hiUS4qqN1i4hTyX4ogA49MEbXgCau",
3
- "Fee": "11",
4
- "Flags": 2147483648,
5
- "LastLedgerSequence": 24268341,
6
- "Sequence": 15177,
7
- "SignerEntries": [
8
- {
9
- "SignerEntry": {
10
- "Account": "r4PQv7BCpp4SAJx3isNpQM8T2BuGrMQs5U",
11
- "SignerWeight": 1
12
- }
13
- },
14
- {
15
- "SignerEntry": {
16
- "Account": "rH7KDR67MZR7LDV7gesmEMXtaqU3FaK7Lr",
17
- "SignerWeight": 1
18
- }
19
- },
20
- {
21
- "SignerEntry": {
22
- "Account": "rPqHsX34XApKSfE4UxKbqVXb3WRmmgMY2u",
23
- "SignerWeight": 1
24
- }
25
- }
26
- ],
27
- "SignerQuorum": 3,
28
- "SigningPubKey": "0315B15964B3704B171E860DE1FC914D283395EE825C8546AEEBF0D24A5802BBC5",
29
- "TransactionType": "SignerListSet",
30
- "TxnSignature": "3044022069FC98D0BC32F510D4F94ECC726613E957D290050E428DD86EDA2C2515A1732D02207064EF085437B3F12A744AC6528D9E0C59FAA5A9FE903DF3639D2F09B522175F",
31
- "date": 527847001,
32
- "hash": "98C33CABFAE9F830CE842C260E34C25B0F987EE691941C0C9225AD476871B73D",
33
- "inLedger": 24268339,
34
- "ledger_index": 24268339,
35
- "meta": {
36
- "AffectedNodes": [
37
- {
38
- "ModifiedNode": {
39
- "FinalFields": {
40
- "Account": "rfCp6hiUS4qqN1i4hTyX4ogA49MEbXgCau",
41
- "Balance": "4556673359",
42
- "Flags": 0,
43
- "OwnerCount": 25,
44
- "RegularKey": "rK7ShY9CeDMBHLNFSMtTrSAUd9uzwcymcL",
45
- "Sequence": 15178
46
- },
47
- "LedgerEntryType": "AccountRoot",
48
- "LedgerIndex": "0DAF42BEE40F0EEFCFD8D54E81ECACD9371D281CDD9B77384FCDAF0E16560A44",
49
- "PreviousFields": {
50
- "Balance": "4556673370",
51
- "Sequence": 15177
52
- },
53
- "PreviousTxnID": "4CD30C2526418A76ABED74713DF144B19F1B29BD8F7BC9EADCF16D33D7EC83D8",
54
- "PreviousTxnLgrSeq": 24265571
55
- }
56
- },
57
- {
58
- "ModifiedNode": {
59
- "FinalFields": {
60
- "Flags": 0,
61
- "OwnerNode": "0000000000000000",
62
- "SignerEntries": [
63
- {
64
- "SignerEntry": {
65
- "Account": "rH7KDR67MZR7LDV7gesmEMXtaqU3FaK7Lr",
66
- "SignerWeight": 1
67
- }
68
- },
69
- {
70
- "SignerEntry": {
71
- "Account": "r4PQv7BCpp4SAJx3isNpQM8T2BuGrMQs5U",
72
- "SignerWeight": 1
73
- }
74
- },
75
- {
76
- "SignerEntry": {
77
- "Account": "rPqHsX34XApKSfE4UxKbqVXb3WRmmgMY2u",
78
- "SignerWeight": 1
79
- }
80
- }
81
- ],
82
- "SignerListID": 0,
83
- "SignerQuorum": 3
84
- },
85
- "LedgerEntryType": "SignerList",
86
- "LedgerIndex": "16F6AEEC6B85C9658B4BF604671677B7A7B2FAAFDB2FA5A0B72CBB49CAE80924"
87
- }
88
- }
89
- ],
90
- "TransactionIndex": 8,
91
- "TransactionResult": "tesSUCCESS"
92
- },
93
- "validated": true
94
- }
@@ -1 +0,0 @@
1
- "12000A240000000E2028000000016840000000000027108114D5024F157225CA9F8F4C73094D61A8FDD746E0DB"
@@ -1,7 +0,0 @@
1
- {
2
- "TransactionType": "TicketCreate",
3
- "TicketCount": 1,
4
- "Account": "rLRH6HciuPv5rQBNFBYH1iPPAuVFERtNXZ",
5
- "Sequence": 14,
6
- "Fee": "10000"
7
- }
@@ -1,188 +0,0 @@
1
- {
2
- "transactions": [{
3
- "rjson": {
4
- "Account": "r3kmLJN5D28dHuH8vZNUZpMC43pEHpaocV",
5
- "Destination": "rLQBHVhFnaC5gLEkgr6HgBJJ3bgeZHg9cj",
6
- "TransactionType": "Payment",
7
- "TxnSignature": "3045022022EB32AECEF7C644C891C19F87966DF9C62B1F34BABA6BE774325E4BB8E2DD62022100A51437898C28C2B297112DF8131F2BB39EA5FE613487DDD611525F1796264639",
8
- "SigningPubKey": "034AADB09CFF4A4804073701EC53C3510CDC95917C2BB0150FB742D0C66E6CEE9E",
9
- "Amount": "10000000000",
10
- "DestinationTag": 1010,
11
- "SourceTag": 84854,
12
- "Fee": "10",
13
- "Flags": 0,
14
- "Sequence": 62
15
- },
16
- "xjson": {
17
- "Account": "X7tFPvjMH7nDxP8nTGkeeggcUpCZj8UbyT2QoiRHGDfjqrB",
18
- "Destination": "XVYmGpJqHS95ir411XvanwY1xt5Z2314WsamHPVgUNABUGV",
19
- "TransactionType": "Payment",
20
- "TxnSignature": "3045022022EB32AECEF7C644C891C19F87966DF9C62B1F34BABA6BE774325E4BB8E2DD62022100A51437898C28C2B297112DF8131F2BB39EA5FE613487DDD611525F1796264639",
21
- "SigningPubKey": "034AADB09CFF4A4804073701EC53C3510CDC95917C2BB0150FB742D0C66E6CEE9E",
22
- "Amount": "10000000000",
23
- "Fee": "10",
24
- "Flags": 0,
25
- "Sequence": 62
26
- }
27
- },
28
- {
29
- "rjson": {
30
- "Account": "r4DymtkgUAh2wqRxVfdd3Xtswzim6eC6c5",
31
- "Amount": "199000000",
32
- "Destination": "rsekGH9p9neiPxym2TMJhqaCzHFuokenTU",
33
- "DestinationTag": 3663729509,
34
- "Fee": "6335",
35
- "Flags": 2147483648,
36
- "LastLedgerSequence": 57313352,
37
- "Sequence": 105791,
38
- "SigningPubKey": "02053A627976CE1157461336AC65290EC1571CAAD1B327339980F7BF65EF776F83",
39
- "TransactionType": "Payment",
40
- "TxnSignature": "30440220086D3330CD6CE01D891A26BA0355D8D5A5D28A5C9A1D0C5E06E321C81A02318A0220027C3F6606E41FEA35103EDE5224CC489B6514ACFE27543185B0419DD02E301C"
41
- },
42
- "xjson": {
43
- "Account": "r4DymtkgUAh2wqRxVfdd3Xtswzim6eC6c5",
44
- "Amount": "199000000",
45
- "Destination": "X7cBoj6a5xSEfPCr6AStN9YPhbMAA2yaN2XYWwRJKAKb3y5",
46
- "Fee": "6335",
47
- "Flags": 2147483648,
48
- "LastLedgerSequence": 57313352,
49
- "Sequence": 105791,
50
- "SigningPubKey": "02053A627976CE1157461336AC65290EC1571CAAD1B327339980F7BF65EF776F83",
51
- "TransactionType": "Payment",
52
- "TxnSignature": "30440220086D3330CD6CE01D891A26BA0355D8D5A5D28A5C9A1D0C5E06E321C81A02318A0220027C3F6606E41FEA35103EDE5224CC489B6514ACFE27543185B0419DD02E301C"
53
- }
54
- },
55
- {
56
- "rjson": {
57
- "Account": "rDsbeomae4FXwgQTJp9Rs64Qg9vDiTCdBv",
58
- "Amount": "105302107",
59
- "Destination": "r33hypJXDs47LVpmvta7hMW9pR8DYeBtkW",
60
- "DestinationTag": 1658156118,
61
- "Fee": "60000",
62
- "Flags": 2147483648,
63
- "LastLedgerSequence": 57313566,
64
- "Sequence": 1113196,
65
- "SigningPubKey": "03D847C2DBED3ABF0453F71DCD7641989136277218DF516AD49519C9693F32727E",
66
- "TransactionType": "Payment",
67
- "TxnSignature": "3045022100FCA10FBAC65EA60C115A970CD52E6A526B1F9DDB6C4F843DA3DE7A97DFF9492D022037824D0FC6F663FB08BE0F2812CBADE1F61836528D44945FC37F10CC03215111"
68
- },
69
- "xjson": {
70
- "Account": "rDsbeomae4FXwgQTJp9Rs64Qg9vDiTCdBv",
71
- "Amount": "105302107",
72
- "Destination": "X7ikFY5asEwp6ikt2AJdTfBLALEs5JN35kkeqKVeT1GdvY1",
73
- "Fee": "60000",
74
- "Flags": 2147483648,
75
- "LastLedgerSequence": 57313566,
76
- "Sequence": 1113196,
77
- "SigningPubKey": "03D847C2DBED3ABF0453F71DCD7641989136277218DF516AD49519C9693F32727E",
78
- "TransactionType": "Payment",
79
- "TxnSignature": "3045022100FCA10FBAC65EA60C115A970CD52E6A526B1F9DDB6C4F843DA3DE7A97DFF9492D022037824D0FC6F663FB08BE0F2812CBADE1F61836528D44945FC37F10CC03215111"
80
- }
81
- },
82
- {
83
- "rjson": {
84
- "Account": "rDsbeomae4FXwgQTJp9Rs64Qg9vDiTCdBv",
85
- "Amount": "3899911571",
86
- "Destination": "rU2mEJSLqBRkYLVTv55rFTgQajkLTnT6mA",
87
- "DestinationTag": 255406,
88
- "Fee": "60000",
89
- "Flags": 2147483648,
90
- "LastLedgerSequence": 57313566,
91
- "Sequence": 1113197,
92
- "SigningPubKey": "03D847C2DBED3ABF0453F71DCD7641989136277218DF516AD49519C9693F32727E",
93
- "TransactionType": "Payment",
94
- "TxnSignature": "3044022077642D94BB3C49BF3CB4C804255EC830D2C6009EA4995E38A84602D579B8AAD702206FAD977C49980226E8B495BF03C8D9767380F1546BBF5A4FD47D604C0D2CCF9B"
95
- },
96
- "xjson": {
97
- "Account": "rDsbeomae4FXwgQTJp9Rs64Qg9vDiTCdBv",
98
- "Amount": "3899911571",
99
- "Destination": "XVfH8gwNWVbB5Kft16jmTNgGTqgw1dzA8ZTBkNjSLw6JdXS",
100
- "Fee": "60000",
101
- "Flags": 2147483648,
102
- "LastLedgerSequence": 57313566,
103
- "Sequence": 1113197,
104
- "SigningPubKey": "03D847C2DBED3ABF0453F71DCD7641989136277218DF516AD49519C9693F32727E",
105
- "TransactionType": "Payment",
106
- "TxnSignature": "3044022077642D94BB3C49BF3CB4C804255EC830D2C6009EA4995E38A84602D579B8AAD702206FAD977C49980226E8B495BF03C8D9767380F1546BBF5A4FD47D604C0D2CCF9B"
107
- }
108
- },
109
- {
110
- "rjson": {
111
- "Account": "r4eEbLKZGbVSBHnSUBZW8i5XaMjGLdqT4a",
112
- "Amount": "820370849",
113
- "Destination": "rDhmyBh4JwDAtXyRZDarNgg52UcLLRoGje",
114
- "DestinationTag": 2017780486,
115
- "Fee": "6000",
116
- "Flags": 2147483648,
117
- "LastLedgerSequence": 57315579,
118
- "Sequence": 234254,
119
- "SigningPubKey": "038CF47114672A12B269AEE015BF7A8438609B994B0640E4B28B2F56E93D948B15",
120
- "TransactionType": "Payment",
121
- "TxnSignature": "3044022015004653B1CBDD5CCA1F7B38555F1B37FE3F811E9D5070281CCC6C8A93460D870220679E9899184901EA69750C8A9325768490B1B9C1A733842446727653FF3D1DC0"
122
- },
123
- "xjson": {
124
- "Account": "r4eEbLKZGbVSBHnSUBZW8i5XaMjGLdqT4a",
125
- "Amount": "820370849",
126
- "Destination": "XV31huWNJQXsAJFwgE6rnC8uf8jRx4H4waq4MyGUxz5CXzS",
127
- "Fee": "6000",
128
- "Flags": 2147483648,
129
- "LastLedgerSequence": 57315579,
130
- "Sequence": 234254,
131
- "SigningPubKey": "038CF47114672A12B269AEE015BF7A8438609B994B0640E4B28B2F56E93D948B15",
132
- "TransactionType": "Payment",
133
- "TxnSignature": "3044022015004653B1CBDD5CCA1F7B38555F1B37FE3F811E9D5070281CCC6C8A93460D870220679E9899184901EA69750C8A9325768490B1B9C1A733842446727653FF3D1DC0"
134
- }
135
- },
136
- {
137
- "rjson": {
138
- "Account": "rsGeDwS4rpocUumu9smpXomzaaeG4Qyifz",
139
- "Amount": "1500000000",
140
- "Destination": "rDxfhNRgCDNDckm45zT5ayhKDC4Ljm7UoP",
141
- "DestinationTag": 1000635172,
142
- "Fee": "5000",
143
- "Flags": 2147483648,
144
- "Sequence": 55741075,
145
- "SigningPubKey": "02ECB814477DF9D8351918878E235EE6AF147A2A5C20F1E71F291F0F3303357C36",
146
- "SourceTag": 1000635172,
147
- "TransactionType": "Payment",
148
- "TxnSignature": "304402202A90972E21823214733082E1977F9EA2D6B5101902F108E7BDD7D128CEEA7AF3022008852C8DAD746A7F18E66A47414FABF551493674783E8EA7409C501D3F05F99A"
149
- },
150
- "xjson": {
151
- "Account": "rsGeDwS4rpocUumu9smpXomzaaeG4Qyifz",
152
- "Amount": "1500000000",
153
- "Destination": "XVBkK1yLutMqFGwTm6hykn7YXGDUrjsZSkpzMgRveZrMbHs",
154
- "Fee": "5000",
155
- "Flags": 2147483648,
156
- "Sequence": 55741075,
157
- "SigningPubKey": "02ECB814477DF9D8351918878E235EE6AF147A2A5C20F1E71F291F0F3303357C36",
158
- "SourceTag": 1000635172,
159
- "TransactionType": "Payment",
160
- "TxnSignature": "304402202A90972E21823214733082E1977F9EA2D6B5101902F108E7BDD7D128CEEA7AF3022008852C8DAD746A7F18E66A47414FABF551493674783E8EA7409C501D3F05F99A"
161
- }
162
- },
163
- {
164
- "rjson": {
165
- "Account": "rHWcuuZoFvDS6gNbmHSdpb7u1hZzxvCoMt",
166
- "Amount": "48918500000",
167
- "Destination": "rEb8TK3gBgk5auZkwc6sHnwrGVJH8DuaLh",
168
- "DestinationTag": 105959914,
169
- "Fee": "10",
170
- "Flags": 2147483648,
171
- "Sequence": 32641,
172
- "SigningPubKey": "02E98DA545CCCC5D14C82594EE9E6CCFCF5171108E2410B3E784183E1068D33429",
173
- "TransactionType": "Payment",
174
- "TxnSignature": "304502210091DCA7AF189CD9DC93BDE24DEAE87381FBF16789C43113EE312241D648982B2402201C6055FEFFF1F119640AAC0B32C4F37375B0A96033E0527A21C1366920D6A524"
175
- },
176
- "xjson": {
177
- "Account": "rHWcuuZoFvDS6gNbmHSdpb7u1hZzxvCoMt",
178
- "Amount": "48918500000",
179
- "Destination": "XVH3aqvbYGhRhrD1FYSzGooNuxdzbG3VR2fuM47oqbXxQr7",
180
- "Fee": "10",
181
- "Flags": 2147483648,
182
- "Sequence": 32641,
183
- "SigningPubKey": "02E98DA545CCCC5D14C82594EE9E6CCFCF5171108E2410B3E784183E1068D33429",
184
- "TransactionType": "Payment",
185
- "TxnSignature": "304502210091DCA7AF189CD9DC93BDE24DEAE87381FBF16789C43113EE312241D648982B2402201C6055FEFFF1F119640AAC0B32C4F37375B0A96033E0527A21C1366920D6A524"
186
- }
187
- }]
188
- }
package/test/hash.test.js DELETED
@@ -1,135 +0,0 @@
1
- const { coreTypes } = require('../src/types')
2
- const { Hash128, Hash160, Hash256, AccountID, Currency } = coreTypes
3
- const { Buffer } = require('buffer/')
4
-
5
- describe('Hash128', function () {
6
- test('has a static width member', function () {
7
- expect(Hash128.width).toBe(16)
8
- })
9
- test('can be unset', function () {
10
- const h1 = Hash128.from('')
11
- expect(h1.toJSON()).toBe('')
12
- })
13
- test('can be compared against another', function () {
14
- const h1 = Hash128.from('100000000000000000000000000000000')
15
- const h2 = Hash128.from('200000000000000000000000000000000')
16
- const h3 = Hash128.from('000000000000000000000000000000003')
17
- expect(h1.lt(h2)).toBe(true)
18
- expect(h3.lt(h2)).toBe(true)
19
- expect(h2.gt(h1)).toBe(true)
20
- expect(h1.gt(h3)).toBe(true)
21
- })
22
- test('throws when constructed from invalid hash length', () => {
23
- expect(() => Hash128.from('1000000000000000000000000000000')).toThrow(
24
- 'Invalid Hash length 15',
25
- )
26
- expect(() => Hash128.from('10000000000000000000000000000000000')).toThrow(
27
- 'Invalid Hash length 17',
28
- )
29
- })
30
- })
31
- describe('Hash160', function () {
32
- test('has a static width member', function () {
33
- expect(Hash160.width).toBe(20)
34
- })
35
- test('inherited by subclasses', function () {
36
- expect(AccountID.width).toBe(20)
37
- expect(Currency.width).toBe(20)
38
- })
39
- test('can be compared against another', function () {
40
- const h1 = Hash160.from('1000000000000000000000000000000000000000')
41
- const h2 = Hash160.from('2000000000000000000000000000000000000000')
42
- const h3 = Hash160.from('0000000000000000000000000000000000000003')
43
- expect(h1.lt(h2)).toBe(true)
44
- expect(h3.lt(h2)).toBe(true)
45
- })
46
- test('throws when constructed from invalid hash length', () => {
47
- expect(() =>
48
- Hash160.from('10000000000000000000000000000000000000'),
49
- ).toThrow('Invalid Hash length 19')
50
- expect(() =>
51
- Hash160.from('100000000000000000000000000000000000000000'),
52
- ).toThrow('Invalid Hash length 21')
53
- })
54
- })
55
-
56
- describe('Hash256', function () {
57
- test('has a static width member', function () {
58
- expect(Hash256.width).toBe(32)
59
- })
60
- test('has a ZERO_256 member', function () {
61
- expect(Hash256.ZERO_256.toJSON()).toBe(
62
- '0000000000000000000000000000000000000000000000000000000000000000',
63
- )
64
- })
65
- test('supports getting the nibblet values at given positions', function () {
66
- const h = Hash256.from(
67
- '1359BD0000000000000000000000000000000000000000000000000000000000',
68
- )
69
- expect(h.nibblet(0)).toBe(0x1)
70
- expect(h.nibblet(1)).toBe(0x3)
71
- expect(h.nibblet(2)).toBe(0x5)
72
- expect(h.nibblet(3)).toBe(0x9)
73
- expect(h.nibblet(4)).toBe(0x0b)
74
- expect(h.nibblet(5)).toBe(0xd)
75
- })
76
- })
77
-
78
- describe('Currency', function () {
79
- test('Decoding allows dodgy XRP without throwing', function () {
80
- const currencyCode = '0000000000000000000000005852500000000000'
81
- expect(Currency.from(currencyCode).toJSON()).toBe(currencyCode)
82
- })
83
- test('Currency code with lowercase letters decodes to ISO code', () => {
84
- expect(Currency.from('xRp').toJSON()).toBe('xRp')
85
- })
86
- test('Currency codes with symbols decodes to ISO code', () => {
87
- expect(Currency.from('x|p').toJSON()).toBe('x|p')
88
- })
89
- test('Currency code with non-standard symbols decodes to hex', () => {
90
- expect(Currency.from(':::').toJSON()).toBe(
91
- '0000000000000000000000003A3A3A0000000000',
92
- )
93
- })
94
- test('Currency codes can be exclusively standard symbols', () => {
95
- expect(Currency.from('![]').toJSON()).toBe('![]')
96
- })
97
- test('Currency codes with uppercase and 0-9 decode to ISO codes', () => {
98
- expect(Currency.from('X8P').toJSON()).toBe('X8P')
99
- expect(Currency.from('USD').toJSON()).toBe('USD')
100
- })
101
-
102
- test('Currency codes with no contiguous zeroes in first 96 type code & reserved bits', function () {
103
- expect(
104
- Currency.from('0000000023410000000000005852520000000000').iso(),
105
- ).toBe(null)
106
- })
107
-
108
- test('Currency codes with no contiguous zeroes in last 40 reserved bits', function () {
109
- expect(
110
- Currency.from('0000000000000000000000005852527570656500').iso(),
111
- ).toBe(null)
112
- })
113
-
114
- test('can be constructed from a Buffer', function () {
115
- const xrp = new Currency(Buffer.alloc(20))
116
- expect(xrp.iso()).toBe('XRP')
117
- })
118
- test('Can handle non-standard currency codes', () => {
119
- const currency = '015841551A748AD2C1F76FF6ECB0CCCD00000000'
120
- expect(Currency.from(currency).toJSON()).toBe(currency)
121
- })
122
-
123
- test('Can handle other non-standard currency codes', () => {
124
- const currency = '0000000000414C6F676F30330000000000000000'
125
- expect(Currency.from(currency).toJSON()).toBe(currency)
126
- })
127
-
128
- test('throws on invalid reprs', function () {
129
- expect(() => Currency.from(Buffer.alloc(19))).toThrow()
130
- expect(() => Currency.from(1)).toThrow()
131
- expect(() =>
132
- Currency.from('00000000000000000000000000000000000000m'),
133
- ).toThrow()
134
- })
135
- })
@@ -1,29 +0,0 @@
1
- const { loadFixture } = require('./utils')
2
- const {
3
- transactionTreeHash,
4
- ledgerHash,
5
- accountStateHash,
6
- } = require('../src/ledger-hashes')
7
-
8
- describe('Ledger Hashes', function () {
9
- function testFactory(ledgerFixture) {
10
- describe(`can calculate hashes for ${ledgerFixture}`, function () {
11
- const ledger = loadFixture(ledgerFixture)
12
- test('computes correct account state hash', function () {
13
- expect(accountStateHash(ledger.accountState).toHex()).toBe(
14
- ledger.account_hash,
15
- )
16
- })
17
- test('computes correct transaction tree hash', function () {
18
- expect(transactionTreeHash(ledger.transactions).toHex()).toBe(
19
- ledger.transaction_hash,
20
- )
21
- })
22
- test('computes correct ledger header hash', function () {
23
- expect(ledgerHash(ledger).toHex()).toBe(ledger.hash)
24
- })
25
- })
26
- }
27
- testFactory('ledger-full-40000.json')
28
- testFactory('ledger-full-38129.json')
29
- })
@@ -1,46 +0,0 @@
1
- const { encode, decode } = require('../src')
2
-
3
- let str =
4
- '1100612200000000240000000125000068652D0000000055B6632D6376A2D9319F20A1C6DCCB486432D1E4A79951229D4C3DE2946F51D56662400009184E72A00081140DD319918CD5AE792BF7EC80D63B0F01B4573BBC'
5
- let lower = str.toLowerCase()
6
-
7
- let bin =
8
- '1100612200000000240000000125000000082D00000000550735A0B32B2A3F4C938B76D6933003E29447DB8C7CE382BBE089402FF12A03E56240000002540BE400811479927BAFFD3D04A26096C0C97B1B0D45B01AD3C0'
9
- let json = {
10
- OwnerCount: 0,
11
- Account: 'rUnFEsHjxqTswbivzL2DNHBb34rhAgZZZK',
12
- PreviousTxnLgrSeq: 8,
13
- LedgerEntryType: 'AccountRoot',
14
- PreviousTxnID:
15
- '0735A0B32B2A3F4C938B76D6933003E29447DB8C7CE382BBE089402FF12A03E5'.toLowerCase(),
16
- Flags: 0,
17
- Sequence: 1,
18
- Balance: '10000000000',
19
- }
20
-
21
- let jsonUpper = {
22
- OwnerCount: 0,
23
- Account: 'rUnFEsHjxqTswbivzL2DNHBb34rhAgZZZK',
24
- PreviousTxnLgrSeq: 8,
25
- LedgerEntryType: 'AccountRoot',
26
- PreviousTxnID:
27
- '0735A0B32B2A3F4C938B76D6933003E29447DB8C7CE382BBE089402FF12A03E5',
28
- Flags: 0,
29
- Sequence: 1,
30
- Balance: '10000000000',
31
- }
32
-
33
- describe('Lowercase hex test', () => {
34
- test('Correctly decodes', () => {
35
- expect(decode(lower)).toEqual(decode(str))
36
- })
37
- test('Re-encodes to uppercase hex', () => {
38
- expect(encode(decode(lower))).toEqual(str)
39
- })
40
- test('Encode when hex field lowercase', () => {
41
- expect(encode(json)).toBe(bin)
42
- })
43
- test('Re-decodes to uppercase hex', () => {
44
- expect(decode(encode(json))).toEqual(jsonUpper)
45
- })
46
- })
@@ -1,38 +0,0 @@
1
- const { encode, decode } = require('../src')
2
-
3
- let json = {
4
- Account: 'rrrrrrrrrrrrrrrrrrrrrhoLvTp',
5
- Sequence: 0,
6
- Fee: '0',
7
- SigningPubKey: '',
8
- Signature: '',
9
- }
10
-
11
- let json_blank_acct = {
12
- Account: '',
13
- Sequence: 0,
14
- Fee: '0',
15
- SigningPubKey: '',
16
- Signature: '',
17
- }
18
-
19
- let binary =
20
- '24000000006840000000000000007300760081140000000000000000000000000000000000000000'
21
-
22
- describe('Can encode Pseudo Transactions', () => {
23
- test('Correctly encodes Pseudo Transaciton', () => {
24
- expect(encode(json)).toEqual(binary)
25
- })
26
-
27
- test('Can decode account objects', () => {
28
- expect(decode(encode(json))).toEqual(json)
29
- })
30
-
31
- test('Blank AccountID is ACCOUNT_ZERO', () => {
32
- expect(encode(json_blank_acct)).toEqual(binary)
33
- })
34
-
35
- test('Decodes Blank AccountID', () => {
36
- expect(decode(encode(json_blank_acct))).toEqual(json)
37
- })
38
- })
@@ -1,15 +0,0 @@
1
- const { quality } = require('../src/coretypes')
2
-
3
- describe('Quality encode/decode', function () {
4
- const bookDirectory =
5
- '4627DFFCFF8B5A265EDBD8AE8C14A52325DBFEDAF4F5C32E5D06F4C3362FE1D0'
6
- const expectedQuality = '195796912.5171664'
7
- test('can decode', function () {
8
- const decimal = quality.decode(bookDirectory)
9
- expect(decimal.toString()).toBe(expectedQuality)
10
- })
11
- test('can encode', function () {
12
- const bytes = quality.encode(expectedQuality)
13
- expect(bytes.toString('hex').toUpperCase()).toBe(bookDirectory.slice(-16))
14
- })
15
- })
@@ -1,89 +0,0 @@
1
- const { ShaMap } = require('../src/shamap')
2
- const { binary, HashPrefix } = require('../src/coretypes')
3
- const { coreTypes } = require('../src/types')
4
- const { loadFixture } = require('./utils')
5
- const { Buffer } = require('buffer/')
6
-
7
- function now() {
8
- return Number(Date.now()) / 1000
9
- }
10
-
11
- const ZERO = '0000000000000000000000000000000000000000000000000000000000000000'
12
-
13
- function makeItem(indexArg) {
14
- let str = indexArg
15
- while (str.length < 64) {
16
- str += '0'
17
- }
18
- const index = coreTypes.Hash256.from(str)
19
- const item = {
20
- toBytesSink(sink) {
21
- index.toBytesSink(sink)
22
- },
23
- hashPrefix() {
24
- return Buffer.from([1, 3, 3, 7])
25
- },
26
- }
27
- return [index, item]
28
- }
29
-
30
- describe('ShaMap', () => {
31
- now()
32
-
33
- test('hashes to zero when empty', () => {
34
- const map = new ShaMap()
35
- expect(map.hash().toHex()).toBe(ZERO)
36
- })
37
- test('creates the same hash no matter which order items are added', () => {
38
- let map = new ShaMap()
39
- const items = [
40
- '0',
41
- '1',
42
- '11',
43
- '7000DE445E22CB9BB7E1717589FA858736BAA5FD192310E20000000000000000',
44
- '7000DE445E22CB9BB7E1717589FA858736BAA5FD192310E21000000000000000',
45
- '7000DE445E22CB9BB7E1717589FA858736BAA5FD192310E22000000000000000',
46
- '7000DE445E22CB9BB7E1717589FA858736BAA5FD192310E23000000000000000',
47
- '12',
48
- '122',
49
- ]
50
- items.forEach((i) => map.addItem(...makeItem(i)))
51
- const h1 = map.hash()
52
- expect(h1.eq(h1)).toBe(true)
53
- map = new ShaMap()
54
- items.reverse().forEach((i) => map.addItem(...makeItem(i)))
55
- expect(map.hash()).toStrictEqual(h1)
56
- })
57
- function factory(fixture) {
58
- test(`recreate account state hash from ${fixture}`, () => {
59
- const map = new ShaMap()
60
- const ledger = loadFixture(fixture)
61
- // const t = now();
62
- const leafNodePrefix = HashPrefix.accountStateEntry
63
- ledger.accountState
64
- .map((e, i) => {
65
- if ((i > 1000) & (i % 1000 === 0)) {
66
- console.log(e.index)
67
- console.log(i)
68
- }
69
- const bytes = binary.serializeObject(e)
70
- return {
71
- index: coreTypes.Hash256.from(e.index),
72
- hashPrefix() {
73
- return leafNodePrefix
74
- },
75
- toBytesSink(sink) {
76
- sink.put(bytes)
77
- },
78
- }
79
- })
80
- .forEach((so) => map.addItem(so.index, so))
81
- expect(map.hash().toHex()).toBe(ledger.account_hash)
82
- // console.log('took seconds: ', (now() - t));
83
- })
84
- }
85
- factory('ledger-full-38129.json')
86
- factory('ledger-full-40000.json')
87
- // factory('ledger-4320277.json');
88
- // factory('14280680.json');
89
- })