@transia/ripple-binary-codec 1.4.4-alpha.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.
- package/LICENSE +13 -0
- package/README.md +107 -0
- package/dist/binary.d.ts +91 -0
- package/dist/binary.js +128 -0
- package/dist/binary.js.map +1 -0
- package/dist/coretypes.d.ts +9 -0
- package/dist/coretypes.js +48 -0
- package/dist/coretypes.js.map +1 -0
- package/dist/enums/bytes.d.ts +26 -0
- package/dist/enums/bytes.js +64 -0
- package/dist/enums/bytes.js.map +1 -0
- package/dist/enums/constants.d.ts +4 -0
- package/dist/enums/constants.js +8 -0
- package/dist/enums/constants.js.map +1 -0
- package/dist/enums/definitions.json +2476 -0
- package/dist/enums/field.d.ts +29 -0
- package/dist/enums/field.js +59 -0
- package/dist/enums/field.js.map +1 -0
- package/dist/enums/index.d.ts +13 -0
- package/dist/enums/index.js +53 -0
- package/dist/enums/index.js.map +1 -0
- package/dist/enums/src/enums/definitions.json +2481 -0
- package/dist/enums/utils-renumber.d.ts +101 -0
- package/dist/enums/utils-renumber.js +127 -0
- package/dist/enums/utils-renumber.js.map +1 -0
- package/dist/enums/xrpl-definitions-base.d.ts +45 -0
- package/dist/enums/xrpl-definitions-base.js +63 -0
- package/dist/enums/xrpl-definitions-base.js.map +1 -0
- package/dist/enums/xrpl-definitions.d.ts +21 -0
- package/dist/enums/xrpl-definitions.js +29 -0
- package/dist/enums/xrpl-definitions.js.map +1 -0
- package/dist/hash-prefixes.d.ts +6 -0
- package/dist/hash-prefixes.js +41 -0
- package/dist/hash-prefixes.js.map +1 -0
- package/dist/hashes.d.ts +51 -0
- package/dist/hashes.js +77 -0
- package/dist/hashes.js.map +1 -0
- package/dist/index.d.ts +64 -0
- package/dist/index.js +139 -0
- package/dist/index.js.map +1 -0
- package/dist/ledger-hashes.d.ts +49 -0
- package/dist/ledger-hashes.js +160 -0
- package/dist/ledger-hashes.js.map +1 -0
- package/dist/quality.d.ts +22 -0
- package/dist/quality.js +40 -0
- package/dist/quality.js.map +1 -0
- package/dist/serdes/binary-parser.d.ts +101 -0
- package/dist/serdes/binary-parser.js +210 -0
- package/dist/serdes/binary-parser.js.map +1 -0
- package/dist/serdes/binary-serializer.d.ts +82 -0
- package/dist/serdes/binary-serializer.js +172 -0
- package/dist/serdes/binary-serializer.js.map +1 -0
- package/dist/shamap.d.ts +103 -0
- package/dist/shamap.js +172 -0
- package/dist/shamap.js.map +1 -0
- package/dist/types/account-id.d.ts +36 -0
- package/dist/types/account-id.js +71 -0
- package/dist/types/account-id.js.map +1 -0
- package/dist/types/amount.d.ts +68 -0
- package/dist/types/amount.js +207 -0
- package/dist/types/amount.js.map +1 -0
- package/dist/types/blob.d.ts +25 -0
- package/dist/types/blob.js +40 -0
- package/dist/types/blob.js.map +1 -0
- package/dist/types/currency.d.ts +29 -0
- package/dist/types/currency.js +127 -0
- package/dist/types/currency.js.map +1 -0
- package/dist/types/hash-128.d.ts +17 -0
- package/dist/types/hash-128.js +32 -0
- package/dist/types/hash-128.js.map +1 -0
- package/dist/types/hash-160.d.ts +11 -0
- package/dist/types/hash-160.js +20 -0
- package/dist/types/hash-160.js.map +1 -0
- package/dist/types/hash-256.d.ts +11 -0
- package/dist/types/hash-256.js +17 -0
- package/dist/types/hash-256.js.map +1 -0
- package/dist/types/hash.d.ts +41 -0
- package/dist/types/hash.js +72 -0
- package/dist/types/hash.js.map +1 -0
- package/dist/types/index.d.ts +18 -0
- package/dist/types/index.js +57 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/issue.d.ts +39 -0
- package/dist/types/issue.js +81 -0
- package/dist/types/issue.js.map +1 -0
- package/dist/types/path-set.d.ts +36 -0
- package/dist/types/path-set.js +233 -0
- package/dist/types/path-set.js.map +1 -0
- package/dist/types/serialized-type.d.ts +63 -0
- package/dist/types/serialized-type.js +97 -0
- package/dist/types/serialized-type.js.map +1 -0
- package/dist/types/st-array.d.ts +28 -0
- package/dist/types/st-array.js +80 -0
- package/dist/types/st-array.js.map +1 -0
- package/dist/types/st-object.d.ts +32 -0
- package/dist/types/st-object.js +149 -0
- package/dist/types/st-object.js.map +1 -0
- package/dist/types/uint-16.d.ts +25 -0
- package/dist/types/uint-16.js +44 -0
- package/dist/types/uint-16.js.map +1 -0
- package/dist/types/uint-32.d.ts +25 -0
- package/dist/types/uint-32.js +49 -0
- package/dist/types/uint-32.js.map +1 -0
- package/dist/types/uint-64.d.ts +39 -0
- package/dist/types/uint-64.js +87 -0
- package/dist/types/uint-64.js.map +1 -0
- package/dist/types/uint-8.d.ts +25 -0
- package/dist/types/uint-8.js +44 -0
- package/dist/types/uint-8.js.map +1 -0
- package/dist/types/uint.d.ts +30 -0
- package/dist/types/uint.js +42 -0
- package/dist/types/uint.js.map +1 -0
- package/dist/types/vector-256.d.ts +31 -0
- package/dist/types/vector-256.js +75 -0
- package/dist/types/vector-256.js.map +1 -0
- package/package.json +47 -0
- package/test/amount.test.js +43 -0
- package/test/binary-json.test.js +45 -0
- package/test/binary-parser.test.js +396 -0
- package/test/binary-serializer.test.js +289 -0
- package/test/definitions.test.js +100 -0
- package/test/fixtures/account-tx-transactions.db +0 -0
- package/test/fixtures/codec-fixtures.json +4466 -0
- package/test/fixtures/data-driven-tests.json +2919 -0
- package/test/fixtures/delivermin-tx-binary.json +1 -0
- package/test/fixtures/delivermin-tx.json +98 -0
- package/test/fixtures/deposit-preauth-tx-binary.json +1 -0
- package/test/fixtures/deposit-preauth-tx-meta-binary.json +1 -0
- package/test/fixtures/deposit-preauth-tx.json +58 -0
- package/test/fixtures/escrow-cancel-binary.json +1 -0
- package/test/fixtures/escrow-cancel-tx.json +6 -0
- package/test/fixtures/escrow-create-binary.json +1 -0
- package/test/fixtures/escrow-create-tx.json +10 -0
- package/test/fixtures/escrow-finish-binary.json +1 -0
- package/test/fixtures/escrow-finish-meta-binary.json +1 -0
- package/test/fixtures/escrow-finish-tx.json +95 -0
- package/test/fixtures/ledger-full-38129.json +1 -0
- package/test/fixtures/ledger-full-40000.json +1 -0
- package/test/fixtures/negative-unl.json +12 -0
- package/test/fixtures/nf-token.json +547 -0
- package/test/fixtures/payment-channel-claim-binary.json +1 -0
- package/test/fixtures/payment-channel-claim-tx.json +8 -0
- package/test/fixtures/payment-channel-create-binary.json +1 -0
- package/test/fixtures/payment-channel-create-tx.json +11 -0
- package/test/fixtures/payment-channel-fund-binary.json +1 -0
- package/test/fixtures/payment-channel-fund-tx.json +7 -0
- package/test/fixtures/signerlistset-tx-binary.json +1 -0
- package/test/fixtures/signerlistset-tx-meta-binary.json +1 -0
- package/test/fixtures/signerlistset-tx.json +94 -0
- package/test/fixtures/ticket-create-binary.json +1 -0
- package/test/fixtures/ticket-create-tx.json +7 -0
- package/test/fixtures/x-codec-fixtures.json +188 -0
- package/test/hash.test.js +135 -0
- package/test/ledger.test.js +29 -0
- package/test/lower-case-hex.test.js +46 -0
- package/test/pseudo-transaction.test.js +38 -0
- package/test/quality.test.js +15 -0
- package/test/shamap.test.js +89 -0
- package/test/signing-data-encoding.test.js +242 -0
- package/test/tx-encode-decode.test.js +119 -0
- package/test/types.test.js +34 -0
- package/test/uint.test.js +148 -0
- package/test/utils.js +30 -0
- package/test/x-address.test.js +181 -0
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
const { encode, decode } = require('./../src/index')
|
|
2
|
+
const fixtures = require('./fixtures/x-codec-fixtures.json')
|
|
3
|
+
|
|
4
|
+
let json_x1 = {
|
|
5
|
+
OwnerCount: 0,
|
|
6
|
+
Account: 'XVXdn5wEVm5G4UhEHWDPqjvdeH361P7BsapL4m2D2XnPSwT',
|
|
7
|
+
PreviousTxnLgrSeq: 7,
|
|
8
|
+
LedgerEntryType: 'AccountRoot',
|
|
9
|
+
PreviousTxnID:
|
|
10
|
+
'DF530FB14C5304852F20080B0A8EEF3A6BDD044F41F4EBBD68B8B321145FE4FF',
|
|
11
|
+
Flags: 0,
|
|
12
|
+
Sequence: 1,
|
|
13
|
+
Balance: '10000000000',
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
let json_r1 = {
|
|
17
|
+
OwnerCount: 0,
|
|
18
|
+
Account: 'rLs1MzkFWCxTbuAHgjeTZK4fcCDDnf2KRv',
|
|
19
|
+
PreviousTxnLgrSeq: 7,
|
|
20
|
+
LedgerEntryType: 'AccountRoot',
|
|
21
|
+
PreviousTxnID:
|
|
22
|
+
'DF530FB14C5304852F20080B0A8EEF3A6BDD044F41F4EBBD68B8B321145FE4FF',
|
|
23
|
+
Flags: 0,
|
|
24
|
+
Sequence: 1,
|
|
25
|
+
Balance: '10000000000',
|
|
26
|
+
SourceTag: 12345,
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
let json_null_x = {
|
|
30
|
+
OwnerCount: 0,
|
|
31
|
+
Account: 'rLs1MzkFWCxTbuAHgjeTZK4fcCDDnf2KRv',
|
|
32
|
+
Destination: 'rLs1MzkFWCxTbuAHgjeTZK4fcCDDnf2KRv',
|
|
33
|
+
Issuer: 'XVXdn5wEVm5G4UhEHWDPqjvdeH361P4GETfNyyXGaoqBj71',
|
|
34
|
+
PreviousTxnLgrSeq: 7,
|
|
35
|
+
LedgerEntryType: 'AccountRoot',
|
|
36
|
+
PreviousTxnID:
|
|
37
|
+
'DF530FB14C5304852F20080B0A8EEF3A6BDD044F41F4EBBD68B8B321145FE4FF',
|
|
38
|
+
Flags: 0,
|
|
39
|
+
Sequence: 1,
|
|
40
|
+
Balance: '10000000000',
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
let json_invalid_x = {
|
|
44
|
+
OwnerCount: 0,
|
|
45
|
+
Account: 'rLs1MzkFWCxTbuAHgjeTZK4fcCDDnf2KRv',
|
|
46
|
+
Destination: 'rLs1MzkFWCxTbuAHgjeTZK4fcCDDnf2KRv',
|
|
47
|
+
Issuer: 'XVXdn5wEVm5g4UhEHWDPqjvdeH361P4GETfNyyXGaoqBj71',
|
|
48
|
+
PreviousTxnLgrSeq: 7,
|
|
49
|
+
LedgerEntryType: 'AccountRoot',
|
|
50
|
+
PreviousTxnID:
|
|
51
|
+
'DF530FB14C5304852F20080B0A8EEF3A6BDD044F41F4EBBD68B8B321145FE4FF',
|
|
52
|
+
Flags: 0,
|
|
53
|
+
Sequence: 1,
|
|
54
|
+
Balance: '10000000000',
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
let json_null_r = {
|
|
58
|
+
OwnerCount: 0,
|
|
59
|
+
Account: 'rLs1MzkFWCxTbuAHgjeTZK4fcCDDnf2KRv',
|
|
60
|
+
Destination: 'rLs1MzkFWCxTbuAHgjeTZK4fcCDDnf2KRv',
|
|
61
|
+
Issuer: 'rLs1MzkFWCxTbuAHgjeTZK4fcCDDnf2KRv',
|
|
62
|
+
PreviousTxnLgrSeq: 7,
|
|
63
|
+
LedgerEntryType: 'AccountRoot',
|
|
64
|
+
PreviousTxnID:
|
|
65
|
+
'DF530FB14C5304852F20080B0A8EEF3A6BDD044F41F4EBBD68B8B321145FE4FF',
|
|
66
|
+
Flags: 0,
|
|
67
|
+
Sequence: 1,
|
|
68
|
+
Balance: '10000000000',
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
let invalid_json_issuer_tagged = {
|
|
72
|
+
OwnerCount: 0,
|
|
73
|
+
Account: 'rLs1MzkFWCxTbuAHgjeTZK4fcCDDnf2KRv',
|
|
74
|
+
Destination: 'rLs1MzkFWCxTbuAHgjeTZK4fcCDDnf2KRv',
|
|
75
|
+
Issuer: 'XVXdn5wEVm5G4UhEHWDPqjvdeH361P7BsapL4m2D2XnPSwT',
|
|
76
|
+
PreviousTxnLgrSeq: 7,
|
|
77
|
+
LedgerEntryType: 'AccountRoot',
|
|
78
|
+
PreviousTxnID:
|
|
79
|
+
'DF530FB14C5304852F20080B0A8EEF3A6BDD044F41F4EBBD68B8B321145FE4FF',
|
|
80
|
+
Flags: 0,
|
|
81
|
+
Sequence: 1,
|
|
82
|
+
Balance: '10000000000',
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
let invalid_json_x_and_tagged = {
|
|
86
|
+
OwnerCount: 0,
|
|
87
|
+
Account: 'XVXdn5wEVm5G4UhEHWDPqjvdeH361P7BsapL4m2D2XnPSwT',
|
|
88
|
+
PreviousTxnLgrSeq: 7,
|
|
89
|
+
LedgerEntryType: 'AccountRoot',
|
|
90
|
+
PreviousTxnID:
|
|
91
|
+
'DF530FB14C5304852F20080B0A8EEF3A6BDD044F41F4EBBD68B8B321145FE4FF',
|
|
92
|
+
Flags: 0,
|
|
93
|
+
Sequence: 1,
|
|
94
|
+
Balance: '10000000000',
|
|
95
|
+
SourceTag: 12345,
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
let json_issued_x = {
|
|
99
|
+
TakerPays: {
|
|
100
|
+
currency: 'USD',
|
|
101
|
+
issuer: 'X7WZKEeNVS2p9Tire9DtNFkzWBZbFtJHWxDjN9fCrBGqVA4',
|
|
102
|
+
value: '7072.8',
|
|
103
|
+
},
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
let json_issued_r = {
|
|
107
|
+
TakerPays: {
|
|
108
|
+
currency: 'USD',
|
|
109
|
+
issuer: 'rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B',
|
|
110
|
+
value: '7072.8',
|
|
111
|
+
},
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
let json_issued_with_tag = {
|
|
115
|
+
TakerPays: {
|
|
116
|
+
currency: 'USD',
|
|
117
|
+
issuer: 'X7WZKEeNVS2p9Tire9DtNFkzWBZbFtSiS2eDBib7svZXuc2',
|
|
118
|
+
value: '7072.8',
|
|
119
|
+
},
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
describe('X-Address Account is equivalent to a classic address w/ SourceTag', () => {
|
|
123
|
+
let encoded_x = encode(json_x1)
|
|
124
|
+
let encoded_r = encode(json_r1)
|
|
125
|
+
test('Can encode with x-Address', () => {
|
|
126
|
+
expect(encoded_x).toEqual(encoded_r)
|
|
127
|
+
})
|
|
128
|
+
|
|
129
|
+
test('decoded X-address is object w/ source and tag', () => {
|
|
130
|
+
let decoded_x = decode(encoded_x)
|
|
131
|
+
expect(decoded_x).toEqual(json_r1)
|
|
132
|
+
})
|
|
133
|
+
|
|
134
|
+
test('Encoding issuer X-Address w/ undefined destination tag', () => {
|
|
135
|
+
expect(encode(json_null_x)).toEqual(encode(json_null_r))
|
|
136
|
+
})
|
|
137
|
+
|
|
138
|
+
test('Throws when X-Address is invalid', () => {
|
|
139
|
+
expect(() => encode(json_invalid_x)).toThrow('checksum_invalid')
|
|
140
|
+
})
|
|
141
|
+
|
|
142
|
+
test('Encodes issued currency w/ x-address', () => {
|
|
143
|
+
expect(encode(json_issued_x)).toEqual(encode(json_issued_r))
|
|
144
|
+
})
|
|
145
|
+
})
|
|
146
|
+
|
|
147
|
+
describe('Invalid X-Address behavior', () => {
|
|
148
|
+
test('X-Address with tag throws value for invalid field', () => {
|
|
149
|
+
expect(() => encode(invalid_json_issuer_tagged)).toThrow(
|
|
150
|
+
new Error('Issuer cannot have an associated tag'),
|
|
151
|
+
)
|
|
152
|
+
})
|
|
153
|
+
|
|
154
|
+
test('Throws when Account has both X-Addr and Destination Tag', () => {
|
|
155
|
+
expect(() => encode(invalid_json_x_and_tagged)).toThrow(
|
|
156
|
+
new Error('Cannot have Account X-Address and SourceTag'),
|
|
157
|
+
)
|
|
158
|
+
})
|
|
159
|
+
|
|
160
|
+
test('Throws when issued currency has tag', () => {
|
|
161
|
+
expect(() => encode(json_issued_with_tag)).toThrow(
|
|
162
|
+
'Only allowed to have tag on Account or Destination',
|
|
163
|
+
)
|
|
164
|
+
})
|
|
165
|
+
})
|
|
166
|
+
|
|
167
|
+
describe('ripple-binary-codec x-address test', function () {
|
|
168
|
+
function makeSuite(name, entries) {
|
|
169
|
+
describe(name, function () {
|
|
170
|
+
entries.forEach((t, testN) => {
|
|
171
|
+
test(`${name}[${testN}] encodes X-address json equivalent to classic address json`, () => {
|
|
172
|
+
expect(encode(t.rjson)).toEqual(encode(t.xjson))
|
|
173
|
+
})
|
|
174
|
+
test(`${name}[${testN}] decodes X-address json equivalent to classic address json`, () => {
|
|
175
|
+
expect(decode(encode(t.xjson))).toEqual(t.rjson)
|
|
176
|
+
})
|
|
177
|
+
})
|
|
178
|
+
})
|
|
179
|
+
}
|
|
180
|
+
makeSuite('transactions', fixtures.transactions)
|
|
181
|
+
})
|