@transia/ripple-binary-codec 1.4.6-alpha.9 → 2.5.1-quantum.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/dist/binary.d.ts +30 -16
- package/dist/binary.js +36 -16
- package/dist/binary.js.map +1 -1
- package/dist/enums/bytes.d.ts +1 -2
- package/dist/enums/bytes.js +1 -2
- package/dist/enums/bytes.js.map +1 -1
- package/dist/enums/constants.d.ts +1 -0
- package/dist/enums/constants.js +6 -5
- package/dist/enums/constants.js.map +1 -1
- package/dist/enums/definitions.json +1535 -919
- package/dist/enums/field.d.ts +1 -2
- package/dist/enums/field.js +1 -2
- package/dist/enums/field.js.map +1 -1
- package/dist/enums/index.d.ts +1 -2
- package/dist/enums/index.js +5 -27
- package/dist/enums/index.js.map +1 -1
- package/dist/enums/src/enums/definitions.json +1537 -921
- package/dist/enums/xrpl-definitions-base.d.ts +5 -3
- package/dist/enums/xrpl-definitions-base.js +26 -6
- package/dist/enums/xrpl-definitions-base.js.map +1 -1
- package/dist/enums/xrpl-definitions.d.ts +2 -1
- package/dist/enums/xrpl-definitions.js +2 -1
- package/dist/enums/xrpl-definitions.js.map +1 -1
- package/dist/hash-prefixes.d.ts +1 -2
- package/dist/hash-prefixes.js +8 -6
- package/dist/hash-prefixes.js.map +1 -1
- package/dist/hashes.d.ts +6 -7
- package/dist/hashes.js +6 -7
- package/dist/hashes.js.map +1 -1
- package/dist/index.d.ts +16 -11
- package/dist/index.js +53 -58
- package/dist/index.js.map +1 -1
- package/dist/ledger-hashes.d.ts +1 -2
- package/dist/ledger-hashes.js +11 -30
- package/dist/ledger-hashes.js.map +1 -1
- package/dist/quality.d.ts +3 -4
- package/dist/quality.js +10 -8
- package/dist/quality.js.map +1 -1
- package/dist/serdes/binary-parser.d.ts +2 -3
- package/dist/serdes/binary-parser.js +16 -32
- package/dist/serdes/binary-parser.js.map +1 -1
- package/dist/serdes/binary-serializer.d.ts +6 -7
- package/dist/serdes/binary-serializer.js +12 -35
- package/dist/serdes/binary-serializer.js.map +1 -1
- package/dist/shamap.d.ts +4 -5
- package/dist/shamap.js +5 -5
- package/dist/shamap.js.map +1 -1
- package/dist/src/binary.d.ts +106 -0
- package/dist/src/binary.js +154 -0
- package/dist/src/binary.js.map +1 -0
- package/dist/src/coretypes.d.ts +9 -0
- package/dist/src/coretypes.js +48 -0
- package/dist/src/coretypes.js.map +1 -0
- package/dist/src/enums/bytes.d.ts +25 -0
- package/dist/src/enums/bytes.js +63 -0
- package/dist/src/enums/bytes.js.map +1 -0
- package/dist/src/enums/constants.d.ts +5 -0
- package/dist/src/enums/constants.js +9 -0
- package/dist/src/enums/constants.js.map +1 -0
- package/dist/src/enums/definitions.json +3385 -0
- package/dist/src/enums/field.d.ts +28 -0
- package/dist/src/enums/field.js +58 -0
- package/dist/src/enums/field.js.map +1 -0
- package/dist/src/enums/index.d.ts +12 -0
- package/dist/src/enums/index.js +31 -0
- package/dist/src/enums/index.js.map +1 -0
- package/dist/src/enums/utils-renumber.d.ts +101 -0
- package/dist/src/enums/utils-renumber.js +127 -0
- package/dist/src/enums/utils-renumber.js.map +1 -0
- package/dist/src/enums/xrpl-definitions-base.d.ts +47 -0
- package/dist/src/enums/xrpl-definitions-base.js +83 -0
- package/dist/src/enums/xrpl-definitions-base.js.map +1 -0
- package/dist/src/enums/xrpl-definitions.d.ts +22 -0
- package/dist/src/enums/xrpl-definitions.js +30 -0
- package/dist/src/enums/xrpl-definitions.js.map +1 -0
- package/dist/src/hash-prefixes.d.ts +5 -0
- package/dist/src/hash-prefixes.js +43 -0
- package/dist/src/hash-prefixes.js.map +1 -0
- package/dist/src/hashes.d.ts +50 -0
- package/dist/src/hashes.js +76 -0
- package/dist/src/hashes.js.map +1 -0
- package/dist/src/index.d.ts +69 -0
- package/dist/src/index.js +134 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/ledger-hashes.d.ts +48 -0
- package/dist/src/ledger-hashes.js +141 -0
- package/dist/src/ledger-hashes.js.map +1 -0
- package/dist/src/quality.d.ts +21 -0
- package/dist/src/quality.js +42 -0
- package/dist/src/quality.js.map +1 -0
- package/dist/src/serdes/binary-parser.d.ts +100 -0
- package/dist/src/serdes/binary-parser.js +194 -0
- package/dist/src/serdes/binary-parser.js.map +1 -0
- package/dist/src/serdes/binary-serializer.d.ts +81 -0
- package/dist/src/serdes/binary-serializer.js +149 -0
- package/dist/src/serdes/binary-serializer.js.map +1 -0
- package/dist/src/shamap.d.ts +102 -0
- package/dist/src/shamap.js +172 -0
- package/dist/src/shamap.js.map +1 -0
- package/dist/src/types/account-id.d.ts +35 -0
- package/dist/src/types/account-id.js +69 -0
- package/dist/src/types/account-id.js.map +1 -0
- package/dist/src/types/amount.d.ts +91 -0
- package/dist/src/types/amount.js +289 -0
- package/dist/src/types/amount.js.map +1 -0
- package/dist/src/types/blob.d.ts +24 -0
- package/dist/src/types/blob.js +43 -0
- package/dist/src/types/blob.js.map +1 -0
- package/dist/src/types/currency.d.ts +28 -0
- package/dist/src/types/currency.js +127 -0
- package/dist/src/types/currency.js.map +1 -0
- package/dist/src/types/hash-128.d.ts +16 -0
- package/dist/src/types/hash-128.js +32 -0
- package/dist/src/types/hash-128.js.map +1 -0
- package/dist/src/types/hash-160.d.ts +10 -0
- package/dist/src/types/hash-160.js +19 -0
- package/dist/src/types/hash-160.js.map +1 -0
- package/dist/src/types/hash-192.d.ts +10 -0
- package/dist/src/types/hash-192.js +19 -0
- package/dist/src/types/hash-192.js.map +1 -0
- package/dist/src/types/hash-256.d.ts +10 -0
- package/dist/src/types/hash-256.js +16 -0
- package/dist/src/types/hash-256.js.map +1 -0
- package/dist/src/types/hash.d.ts +40 -0
- package/dist/src/types/hash.js +76 -0
- package/dist/src/types/hash.js.map +1 -0
- package/dist/src/types/index.d.ts +19 -0
- package/dist/src/types/index.js +66 -0
- package/dist/src/types/index.js.map +1 -0
- package/dist/src/types/issue.d.ts +48 -0
- package/dist/src/types/issue.js +104 -0
- package/dist/src/types/issue.js.map +1 -0
- package/dist/src/types/path-set.d.ts +36 -0
- package/dist/src/types/path-set.js +233 -0
- package/dist/src/types/path-set.js.map +1 -0
- package/dist/src/types/serialized-type.d.ts +70 -0
- package/dist/src/types/serialized-type.js +105 -0
- package/dist/src/types/serialized-type.js.map +1 -0
- package/dist/src/types/st-array.d.ts +31 -0
- package/dist/src/types/st-array.js +86 -0
- package/dist/src/types/st-array.js.map +1 -0
- package/dist/src/types/st-number.d.ts +54 -0
- package/dist/src/types/st-number.js +208 -0
- package/dist/src/types/st-number.js.map +1 -0
- package/dist/src/types/st-object.d.ts +32 -0
- package/dist/src/types/st-object.js +173 -0
- package/dist/src/types/st-object.js.map +1 -0
- package/dist/src/types/uint-16.d.ts +24 -0
- package/dist/src/types/uint-16.js +45 -0
- package/dist/src/types/uint-16.js.map +1 -0
- package/dist/src/types/uint-32.d.ts +24 -0
- package/dist/src/types/uint-32.js +50 -0
- package/dist/src/types/uint-32.js.map +1 -0
- package/dist/src/types/uint-64.d.ts +38 -0
- package/dist/src/types/uint-64.js +107 -0
- package/dist/src/types/uint-64.js.map +1 -0
- package/dist/src/types/uint-8.d.ts +24 -0
- package/dist/src/types/uint-8.js +46 -0
- package/dist/src/types/uint-8.js.map +1 -0
- package/dist/src/types/uint.d.ts +29 -0
- package/dist/src/types/uint.js +47 -0
- package/dist/src/types/uint.js.map +1 -0
- package/dist/src/types/vector-256.d.ts +30 -0
- package/dist/src/types/vector-256.js +73 -0
- package/dist/src/types/vector-256.js.map +1 -0
- package/dist/src/types/xchain-bridge.d.ts +44 -0
- package/dist/src/types/xchain-bridge.js +102 -0
- package/dist/src/types/xchain-bridge.js.map +1 -0
- package/dist/src/utils.d.ts +79 -0
- package/dist/src/utils.js +181 -0
- package/dist/src/utils.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/types/account-id.d.ts +1 -2
- package/dist/types/account-id.js +4 -6
- package/dist/types/account-id.js.map +1 -1
- package/dist/types/amount.d.ts +31 -8
- package/dist/types/amount.js +125 -43
- package/dist/types/amount.js.map +1 -1
- package/dist/types/blob.d.ts +1 -2
- package/dist/types/blob.js +5 -2
- package/dist/types/blob.js.map +1 -1
- package/dist/types/currency.d.ts +1 -2
- package/dist/types/currency.js +13 -13
- package/dist/types/currency.js.map +1 -1
- package/dist/types/hash-128.d.ts +1 -2
- package/dist/types/hash-128.js +3 -3
- package/dist/types/hash-128.js.map +1 -1
- package/dist/types/hash-160.d.ts +1 -2
- package/dist/types/hash-160.js +1 -2
- package/dist/types/hash-160.js.map +1 -1
- package/dist/types/hash-192.d.ts +10 -0
- package/dist/types/hash-192.js +19 -0
- package/dist/types/hash-192.js.map +1 -0
- package/dist/types/hash-256.d.ts +1 -2
- package/dist/types/hash-256.js +1 -2
- package/dist/types/hash-256.js.map +1 -1
- package/dist/types/hash.d.ts +2 -3
- package/dist/types/hash.js +8 -4
- package/dist/types/hash.js.map +1 -1
- package/dist/types/index.d.ts +2 -1
- package/dist/types/index.js +11 -2
- package/dist/types/index.js.map +1 -1
- package/dist/types/issue.d.ts +48 -0
- package/dist/types/issue.js +104 -0
- package/dist/types/issue.js.map +1 -0
- package/dist/types/path-set.js +12 -12
- package/dist/types/path-set.js.map +1 -1
- package/dist/types/serialized-type.d.ts +23 -16
- package/dist/types/serialized-type.js +15 -7
- package/dist/types/serialized-type.js.map +1 -1
- package/dist/types/st-array.d.ts +5 -2
- package/dist/types/st-array.js +17 -11
- package/dist/types/st-array.js.map +1 -1
- package/dist/types/st-number.d.ts +54 -0
- package/dist/types/st-number.js +208 -0
- package/dist/types/st-number.js.map +1 -0
- package/dist/types/st-object.js +32 -8
- package/dist/types/st-object.js.map +1 -1
- package/dist/types/uint-16.d.ts +1 -2
- package/dist/types/uint-16.js +6 -5
- package/dist/types/uint-16.js.map +1 -1
- package/dist/types/uint-32.d.ts +1 -2
- package/dist/types/uint-32.js +7 -6
- package/dist/types/uint-32.js.map +1 -1
- package/dist/types/uint-64.d.ts +6 -7
- package/dist/types/uint-64.js +44 -24
- package/dist/types/uint-64.js.map +1 -1
- package/dist/types/uint-8.d.ts +1 -2
- package/dist/types/uint-8.js +7 -5
- package/dist/types/uint-8.js.map +1 -1
- package/dist/types/uint.d.ts +5 -6
- package/dist/types/uint.js +5 -0
- package/dist/types/uint.js.map +1 -1
- package/dist/types/vector-256.d.ts +1 -2
- package/dist/types/vector-256.js +2 -4
- package/dist/types/vector-256.js.map +1 -1
- package/dist/types/xchain-bridge.d.ts +44 -0
- package/dist/types/xchain-bridge.js +102 -0
- package/dist/types/xchain-bridge.js.map +1 -0
- package/dist/utils.d.ts +79 -0
- package/dist/utils.js +181 -0
- package/dist/utils.js.map +1 -0
- package/package.json +21 -17
- package/src/README.md +5 -0
- package/src/binary.ts +235 -0
- package/src/coretypes.ts +31 -0
- package/src/enums/README.md +144 -0
- package/src/enums/bytes.ts +74 -0
- package/src/enums/constants.ts +5 -0
- package/src/enums/definitions.json +3390 -0
- package/src/enums/field.ts +84 -0
- package/src/enums/index.ts +34 -0
- package/src/enums/utils-renumber.ts +134 -0
- package/src/enums/xrpl-definitions-base.ts +150 -0
- package/src/enums/xrpl-definitions.ts +33 -0
- package/src/hash-prefixes.ts +42 -0
- package/src/hashes.ts +75 -0
- package/src/index.ts +166 -0
- package/src/ledger-hashes.ts +191 -0
- package/src/quality.ts +38 -0
- package/src/serdes/binary-parser.ts +228 -0
- package/src/serdes/binary-serializer.ts +166 -0
- package/src/shamap.ts +186 -0
- package/src/types/account-id.ts +86 -0
- package/src/types/amount.ts +362 -0
- package/src/types/blob.ts +46 -0
- package/src/types/currency.ts +140 -0
- package/src/types/hash-128.ts +33 -0
- package/src/types/hash-160.ts +19 -0
- package/src/types/hash-192.ts +19 -0
- package/src/types/hash-256.ts +15 -0
- package/src/types/hash.ts +86 -0
- package/src/types/index.ts +68 -0
- package/src/types/issue.ts +136 -0
- package/src/types/path-set.ts +290 -0
- package/src/types/serialized-type.ts +122 -0
- package/src/types/st-array.ts +113 -0
- package/src/types/st-number.ts +233 -0
- package/src/types/st-object.ts +215 -0
- package/src/types/uint-16.ts +53 -0
- package/src/types/uint-32.ts +59 -0
- package/src/types/uint-64.ts +135 -0
- package/src/types/uint-8.ts +52 -0
- package/src/types/uint.ts +60 -0
- package/src/types/vector-256.ts +79 -0
- package/src/types/xchain-bridge.ts +128 -0
- package/src/utils.ts +220 -0
- package/test/amount.test.js +0 -43
- package/test/binary-json.test.js +0 -45
- package/test/binary-parser.test.js +0 -396
- package/test/binary-serializer.test.js +0 -319
- package/test/definitions.test.js +0 -100
- package/test/fixtures/account-tx-transactions.db +0 -0
- package/test/fixtures/codec-fixtures.json +0 -4466
- package/test/fixtures/data-driven-tests.json +0 -2919
- package/test/fixtures/delivermin-tx-binary.json +0 -1
- package/test/fixtures/delivermin-tx.json +0 -98
- package/test/fixtures/deposit-preauth-tx-binary.json +0 -1
- package/test/fixtures/deposit-preauth-tx-meta-binary.json +0 -1
- package/test/fixtures/deposit-preauth-tx.json +0 -58
- package/test/fixtures/escrow-cancel-binary.json +0 -1
- package/test/fixtures/escrow-cancel-tx.json +0 -6
- package/test/fixtures/escrow-create-binary.json +0 -1
- package/test/fixtures/escrow-create-tx.json +0 -10
- package/test/fixtures/escrow-finish-binary.json +0 -1
- package/test/fixtures/escrow-finish-meta-binary.json +0 -1
- package/test/fixtures/escrow-finish-tx.json +0 -95
- package/test/fixtures/ledger-full-38129.json +0 -1
- package/test/fixtures/ledger-full-40000.json +0 -1
- package/test/fixtures/negative-unl.json +0 -12
- package/test/fixtures/nf-token.json +0 -547
- package/test/fixtures/payment-channel-claim-binary.json +0 -1
- package/test/fixtures/payment-channel-claim-tx.json +0 -8
- package/test/fixtures/payment-channel-create-binary.json +0 -1
- package/test/fixtures/payment-channel-create-tx.json +0 -11
- package/test/fixtures/payment-channel-fund-binary.json +0 -1
- package/test/fixtures/payment-channel-fund-tx.json +0 -7
- package/test/fixtures/remit-binary.json +0 -1
- package/test/fixtures/remit-tx.json +0 -39
- package/test/fixtures/signerlistset-tx-binary.json +0 -1
- package/test/fixtures/signerlistset-tx-meta-binary.json +0 -1
- package/test/fixtures/signerlistset-tx.json +0 -94
- package/test/fixtures/ticket-create-binary.json +0 -1
- package/test/fixtures/ticket-create-tx.json +0 -7
- package/test/fixtures/unl-report-binary.json +0 -1
- package/test/fixtures/unl-report-meta-binary.json +0 -1
- package/test/fixtures/unl-report.json +0 -89
- package/test/fixtures/x-codec-fixtures.json +0 -188
- package/test/hash.test.js +0 -135
- package/test/ledger.test.js +0 -29
- package/test/lower-case-hex.test.js +0 -46
- package/test/pseudo-transaction.test.js +0 -38
- package/test/quality.test.js +0 -15
- package/test/shamap.test.js +0 -89
- package/test/signing-data-encoding.test.js +0 -213
- package/test/tx-encode-decode.test.js +0 -119
- package/test/types.test.js +0 -34
- package/test/uint.test.js +0 -148
- package/test/utils.js +0 -30
- package/test/x-address.test.js +0 -181
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { Hash256 } from './types';
|
|
2
|
+
import { BytesList } from './serdes/binary-serializer';
|
|
3
|
+
/**
|
|
4
|
+
* Class for hashing with SHA512
|
|
5
|
+
* @extends BytesList So SerializedTypes can write bytes to a Sha512Half
|
|
6
|
+
*/
|
|
7
|
+
declare class Sha512Half extends BytesList {
|
|
8
|
+
private hash;
|
|
9
|
+
/**
|
|
10
|
+
* Construct a new Sha512Hash and write bytes this.hash
|
|
11
|
+
*
|
|
12
|
+
* @param bytes bytes to write to this.hash
|
|
13
|
+
* @returns the new Sha512Hash object
|
|
14
|
+
*/
|
|
15
|
+
static put(bytes: Uint8Array): Sha512Half;
|
|
16
|
+
/**
|
|
17
|
+
* Write bytes to an existing Sha512Hash
|
|
18
|
+
*
|
|
19
|
+
* @param bytes bytes to write to object
|
|
20
|
+
* @returns the Sha512 object
|
|
21
|
+
*/
|
|
22
|
+
put(bytes: Uint8Array): Sha512Half;
|
|
23
|
+
/**
|
|
24
|
+
* Compute SHA512 hash and slice in half
|
|
25
|
+
*
|
|
26
|
+
* @returns half of a SHA512 hash
|
|
27
|
+
*/
|
|
28
|
+
finish256(): Uint8Array;
|
|
29
|
+
/**
|
|
30
|
+
* Constructs a Hash256 from the Sha512Half object
|
|
31
|
+
*
|
|
32
|
+
* @returns a Hash256 object
|
|
33
|
+
*/
|
|
34
|
+
finish(): Hash256;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* compute SHA512 hash of a list of bytes
|
|
38
|
+
*
|
|
39
|
+
* @param args zero or more arguments to hash
|
|
40
|
+
* @returns the sha512half hash of the arguments.
|
|
41
|
+
*/
|
|
42
|
+
declare function sha512Half(...args: Uint8Array[]): Uint8Array;
|
|
43
|
+
/**
|
|
44
|
+
* Construct a transactionID from a Serialized Transaction
|
|
45
|
+
*
|
|
46
|
+
* @param serialized bytes to hash
|
|
47
|
+
* @returns a Hash256 object
|
|
48
|
+
*/
|
|
49
|
+
declare function transactionID(serialized: Uint8Array): Hash256;
|
|
50
|
+
export { Sha512Half, sha512Half, transactionID };
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.transactionID = exports.sha512Half = exports.Sha512Half = void 0;
|
|
4
|
+
const hash_prefixes_1 = require("./hash-prefixes");
|
|
5
|
+
const types_1 = require("./types");
|
|
6
|
+
const binary_serializer_1 = require("./serdes/binary-serializer");
|
|
7
|
+
const sha512_1 = require("@transia/isomorphic/sha512");
|
|
8
|
+
/**
|
|
9
|
+
* Class for hashing with SHA512
|
|
10
|
+
* @extends BytesList So SerializedTypes can write bytes to a Sha512Half
|
|
11
|
+
*/
|
|
12
|
+
class Sha512Half extends binary_serializer_1.BytesList {
|
|
13
|
+
constructor() {
|
|
14
|
+
super(...arguments);
|
|
15
|
+
this.hash = sha512_1.sha512.create();
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Construct a new Sha512Hash and write bytes this.hash
|
|
19
|
+
*
|
|
20
|
+
* @param bytes bytes to write to this.hash
|
|
21
|
+
* @returns the new Sha512Hash object
|
|
22
|
+
*/
|
|
23
|
+
static put(bytes) {
|
|
24
|
+
return new Sha512Half().put(bytes);
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Write bytes to an existing Sha512Hash
|
|
28
|
+
*
|
|
29
|
+
* @param bytes bytes to write to object
|
|
30
|
+
* @returns the Sha512 object
|
|
31
|
+
*/
|
|
32
|
+
put(bytes) {
|
|
33
|
+
this.hash.update(bytes);
|
|
34
|
+
return this;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Compute SHA512 hash and slice in half
|
|
38
|
+
*
|
|
39
|
+
* @returns half of a SHA512 hash
|
|
40
|
+
*/
|
|
41
|
+
finish256() {
|
|
42
|
+
return Uint8Array.from(this.hash.digest().slice(0, 32));
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Constructs a Hash256 from the Sha512Half object
|
|
46
|
+
*
|
|
47
|
+
* @returns a Hash256 object
|
|
48
|
+
*/
|
|
49
|
+
finish() {
|
|
50
|
+
return new types_1.Hash256(this.finish256());
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
exports.Sha512Half = Sha512Half;
|
|
54
|
+
/**
|
|
55
|
+
* compute SHA512 hash of a list of bytes
|
|
56
|
+
*
|
|
57
|
+
* @param args zero or more arguments to hash
|
|
58
|
+
* @returns the sha512half hash of the arguments.
|
|
59
|
+
*/
|
|
60
|
+
function sha512Half(...args) {
|
|
61
|
+
const hash = new Sha512Half();
|
|
62
|
+
args.forEach((a) => hash.put(a));
|
|
63
|
+
return hash.finish256();
|
|
64
|
+
}
|
|
65
|
+
exports.sha512Half = sha512Half;
|
|
66
|
+
/**
|
|
67
|
+
* Construct a transactionID from a Serialized Transaction
|
|
68
|
+
*
|
|
69
|
+
* @param serialized bytes to hash
|
|
70
|
+
* @returns a Hash256 object
|
|
71
|
+
*/
|
|
72
|
+
function transactionID(serialized) {
|
|
73
|
+
return new types_1.Hash256(sha512Half(hash_prefixes_1.HashPrefix.transactionID, serialized));
|
|
74
|
+
}
|
|
75
|
+
exports.transactionID = transactionID;
|
|
76
|
+
//# sourceMappingURL=hashes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hashes.js","sourceRoot":"","sources":["../../src/hashes.ts"],"names":[],"mappings":";;;AAAA,mDAA4C;AAC5C,mCAAiC;AACjC,kEAAsD;AACtD,uDAAmD;AAEnD;;;GAGG;AACH,MAAM,UAAW,SAAQ,6BAAS;IAAlC;;QACU,SAAI,GAAG,eAAM,CAAC,MAAM,EAAE,CAAA;IAwChC,CAAC;IAtCC;;;;;OAKG;IACH,MAAM,CAAC,GAAG,CAAC,KAAiB;QAC1B,OAAO,IAAI,UAAU,EAAE,CAAC,GAAG,CAAC,KAAK,CAAC,CAAA;IACpC,CAAC;IAED;;;;;OAKG;IACH,GAAG,CAAC,KAAiB;QACnB,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;QACvB,OAAO,IAAI,CAAA;IACb,CAAC;IAED;;;;OAIG;IACH,SAAS;QACP,OAAO,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAA;IACzD,CAAC;IAED;;;;OAIG;IACH,MAAM;QACJ,OAAO,IAAI,eAAO,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC,CAAA;IACtC,CAAC;CACF;AAwBQ,gCAAU;AAtBnB;;;;;GAKG;AACH,SAAS,UAAU,CAAC,GAAG,IAAkB;IACvC,MAAM,IAAI,GAAG,IAAI,UAAU,EAAE,CAAA;IAC7B,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAA;IAChC,OAAO,IAAI,CAAC,SAAS,EAAE,CAAA;AACzB,CAAC;AAYoB,gCAAU;AAV/B;;;;;GAKG;AACH,SAAS,aAAa,CAAC,UAAsB;IAC3C,OAAO,IAAI,eAAO,CAAC,UAAU,CAAC,0BAAU,CAAC,aAAa,EAAE,UAAU,CAAC,CAAC,CAAA;AACtE,CAAC;AAEgC,sCAAa"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { decodeLedgerData } from './ledger-hashes';
|
|
2
|
+
import { JsonObject } from './types/serialized-type';
|
|
3
|
+
import { XrplDefinitionsBase, TRANSACTION_TYPES, DEFAULT_DEFINITIONS } from './enums';
|
|
4
|
+
import { XrplDefinitions } from './enums/xrpl-definitions';
|
|
5
|
+
import { coreTypes } from './types';
|
|
6
|
+
/**
|
|
7
|
+
* Decode a transaction
|
|
8
|
+
*
|
|
9
|
+
* @param binary hex-string of the encoded transaction
|
|
10
|
+
* @param definitions Custom rippled types to use instead of the default. Used for sidechains and amendments.
|
|
11
|
+
* @returns the JSON representation of the transaction
|
|
12
|
+
*/
|
|
13
|
+
declare function decode(binary: string, definitions?: XrplDefinitionsBase): JsonObject;
|
|
14
|
+
/**
|
|
15
|
+
* Encode a transaction
|
|
16
|
+
*
|
|
17
|
+
* @param json The JSON representation of a transaction
|
|
18
|
+
* @param definitions Custom rippled types to use instead of the default. Used for sidechains and amendments.
|
|
19
|
+
*
|
|
20
|
+
* @returns A hex-string of the encoded transaction
|
|
21
|
+
*/
|
|
22
|
+
declare function encode(json: object, definitions?: XrplDefinitionsBase): string;
|
|
23
|
+
/**
|
|
24
|
+
* Encode a transaction and prepare for signing
|
|
25
|
+
*
|
|
26
|
+
* @param json JSON object representing the transaction
|
|
27
|
+
* @param signer string representing the account to sign the transaction with
|
|
28
|
+
* @param definitions Custom rippled types to use instead of the default. Used for sidechains and amendments.
|
|
29
|
+
* @returns a hex string of the encoded transaction
|
|
30
|
+
*/
|
|
31
|
+
declare function encodeForSigning(json: object, definitions?: XrplDefinitionsBase): string;
|
|
32
|
+
/**
|
|
33
|
+
* Encode a payment channel claim for signing.
|
|
34
|
+
*
|
|
35
|
+
* @param json JSON object representing the claim.
|
|
36
|
+
* @returns a hex string of the encoded claim.
|
|
37
|
+
*/
|
|
38
|
+
declare function encodeForSigningClaim(json: object): string;
|
|
39
|
+
/**
|
|
40
|
+
* Encode a transaction and prepare for multi-signing.
|
|
41
|
+
*
|
|
42
|
+
* @param json JSON object representing the transaction.
|
|
43
|
+
* @param signer string representing the account to sign the transaction with.
|
|
44
|
+
* @param definitions Custom rippled types to use instead of the default. Used for sidechains and amendments.
|
|
45
|
+
* @returns a hex string of the encoded transaction.
|
|
46
|
+
*/
|
|
47
|
+
declare function encodeForMultisigning(json: object, signer: string, definitions?: XrplDefinitionsBase): string;
|
|
48
|
+
/**
|
|
49
|
+
* Encode a Batch transaction for signing.
|
|
50
|
+
*
|
|
51
|
+
* @param json JSON object representing the transaction.
|
|
52
|
+
* @returns a hex string of the encoded transaction.
|
|
53
|
+
*/
|
|
54
|
+
declare function encodeForSigningBatch(json: object): string;
|
|
55
|
+
/**
|
|
56
|
+
* Encode a quality value
|
|
57
|
+
*
|
|
58
|
+
* @param value string representation of a number
|
|
59
|
+
* @returns a hex-string representing the quality
|
|
60
|
+
*/
|
|
61
|
+
declare function encodeQuality(value: string): string;
|
|
62
|
+
/**
|
|
63
|
+
* Decode a quality value
|
|
64
|
+
*
|
|
65
|
+
* @param value hex-string of a quality
|
|
66
|
+
* @returns a string representing the quality
|
|
67
|
+
*/
|
|
68
|
+
declare function decodeQuality(value: string): string;
|
|
69
|
+
export { decode, encode, encodeForSigning, encodeForSigningClaim, encodeForMultisigning, encodeForSigningBatch, encodeQuality, decodeQuality, decodeLedgerData, TRANSACTION_TYPES, XrplDefinitions, XrplDefinitionsBase, DEFAULT_DEFINITIONS, coreTypes, };
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.coreTypes = exports.DEFAULT_DEFINITIONS = exports.XrplDefinitionsBase = exports.XrplDefinitions = exports.TRANSACTION_TYPES = exports.decodeLedgerData = exports.decodeQuality = exports.encodeQuality = exports.encodeForSigningBatch = exports.encodeForMultisigning = exports.encodeForSigningClaim = exports.encodeForSigning = exports.encode = exports.decode = void 0;
|
|
4
|
+
const coretypes_1 = require("./coretypes");
|
|
5
|
+
const ledger_hashes_1 = require("./ledger-hashes");
|
|
6
|
+
Object.defineProperty(exports, "decodeLedgerData", { enumerable: true, get: function () { return ledger_hashes_1.decodeLedgerData; } });
|
|
7
|
+
const enums_1 = require("./enums");
|
|
8
|
+
Object.defineProperty(exports, "XrplDefinitionsBase", { enumerable: true, get: function () { return enums_1.XrplDefinitionsBase; } });
|
|
9
|
+
Object.defineProperty(exports, "TRANSACTION_TYPES", { enumerable: true, get: function () { return enums_1.TRANSACTION_TYPES; } });
|
|
10
|
+
Object.defineProperty(exports, "DEFAULT_DEFINITIONS", { enumerable: true, get: function () { return enums_1.DEFAULT_DEFINITIONS; } });
|
|
11
|
+
const xrpl_definitions_1 = require("./enums/xrpl-definitions");
|
|
12
|
+
Object.defineProperty(exports, "XrplDefinitions", { enumerable: true, get: function () { return xrpl_definitions_1.XrplDefinitions; } });
|
|
13
|
+
const types_1 = require("./types");
|
|
14
|
+
Object.defineProperty(exports, "coreTypes", { enumerable: true, get: function () { return types_1.coreTypes; } });
|
|
15
|
+
const utils_1 = require("@transia/isomorphic/utils");
|
|
16
|
+
const { signingData, signingClaimData, multiSigningData, signingBatchData, binaryToJSON, serializeObject, } = coretypes_1.binary;
|
|
17
|
+
/**
|
|
18
|
+
* Decode a transaction
|
|
19
|
+
*
|
|
20
|
+
* @param binary hex-string of the encoded transaction
|
|
21
|
+
* @param definitions Custom rippled types to use instead of the default. Used for sidechains and amendments.
|
|
22
|
+
* @returns the JSON representation of the transaction
|
|
23
|
+
*/
|
|
24
|
+
function decode(binary, definitions) {
|
|
25
|
+
if (typeof binary !== 'string') {
|
|
26
|
+
throw new Error('binary must be a hex string');
|
|
27
|
+
}
|
|
28
|
+
return binaryToJSON(binary, definitions);
|
|
29
|
+
}
|
|
30
|
+
exports.decode = decode;
|
|
31
|
+
/**
|
|
32
|
+
* Encode a transaction
|
|
33
|
+
*
|
|
34
|
+
* @param json The JSON representation of a transaction
|
|
35
|
+
* @param definitions Custom rippled types to use instead of the default. Used for sidechains and amendments.
|
|
36
|
+
*
|
|
37
|
+
* @returns A hex-string of the encoded transaction
|
|
38
|
+
*/
|
|
39
|
+
function encode(json, definitions) {
|
|
40
|
+
if (typeof json !== 'object') {
|
|
41
|
+
throw new Error();
|
|
42
|
+
}
|
|
43
|
+
return (0, utils_1.bytesToHex)(serializeObject(json, { definitions }));
|
|
44
|
+
}
|
|
45
|
+
exports.encode = encode;
|
|
46
|
+
/**
|
|
47
|
+
* Encode a transaction and prepare for signing
|
|
48
|
+
*
|
|
49
|
+
* @param json JSON object representing the transaction
|
|
50
|
+
* @param signer string representing the account to sign the transaction with
|
|
51
|
+
* @param definitions Custom rippled types to use instead of the default. Used for sidechains and amendments.
|
|
52
|
+
* @returns a hex string of the encoded transaction
|
|
53
|
+
*/
|
|
54
|
+
function encodeForSigning(json, definitions) {
|
|
55
|
+
if (typeof json !== 'object') {
|
|
56
|
+
throw new Error();
|
|
57
|
+
}
|
|
58
|
+
return (0, utils_1.bytesToHex)(signingData(json, coretypes_1.HashPrefix.transactionSig, {
|
|
59
|
+
definitions,
|
|
60
|
+
}));
|
|
61
|
+
}
|
|
62
|
+
exports.encodeForSigning = encodeForSigning;
|
|
63
|
+
/**
|
|
64
|
+
* Encode a payment channel claim for signing.
|
|
65
|
+
*
|
|
66
|
+
* @param json JSON object representing the claim.
|
|
67
|
+
* @returns a hex string of the encoded claim.
|
|
68
|
+
*/
|
|
69
|
+
function encodeForSigningClaim(json) {
|
|
70
|
+
if (typeof json !== 'object') {
|
|
71
|
+
throw new Error();
|
|
72
|
+
}
|
|
73
|
+
return (0, utils_1.bytesToHex)(signingClaimData(json));
|
|
74
|
+
}
|
|
75
|
+
exports.encodeForSigningClaim = encodeForSigningClaim;
|
|
76
|
+
/**
|
|
77
|
+
* Encode a transaction and prepare for multi-signing.
|
|
78
|
+
*
|
|
79
|
+
* @param json JSON object representing the transaction.
|
|
80
|
+
* @param signer string representing the account to sign the transaction with.
|
|
81
|
+
* @param definitions Custom rippled types to use instead of the default. Used for sidechains and amendments.
|
|
82
|
+
* @returns a hex string of the encoded transaction.
|
|
83
|
+
*/
|
|
84
|
+
function encodeForMultisigning(json, signer, definitions) {
|
|
85
|
+
if (typeof json !== 'object') {
|
|
86
|
+
throw new Error();
|
|
87
|
+
}
|
|
88
|
+
if (json['SigningPubKey'] !== '') {
|
|
89
|
+
throw new Error();
|
|
90
|
+
}
|
|
91
|
+
const definitionsOpt = definitions ? { definitions } : undefined;
|
|
92
|
+
return (0, utils_1.bytesToHex)(multiSigningData(json, signer, definitionsOpt));
|
|
93
|
+
}
|
|
94
|
+
exports.encodeForMultisigning = encodeForMultisigning;
|
|
95
|
+
/**
|
|
96
|
+
* Encode a Batch transaction for signing.
|
|
97
|
+
*
|
|
98
|
+
* @param json JSON object representing the transaction.
|
|
99
|
+
* @returns a hex string of the encoded transaction.
|
|
100
|
+
*/
|
|
101
|
+
function encodeForSigningBatch(json) {
|
|
102
|
+
if (typeof json !== 'object') {
|
|
103
|
+
throw new Error('Need an object to encode a Batch transaction');
|
|
104
|
+
}
|
|
105
|
+
return (0, utils_1.bytesToHex)(signingBatchData(json));
|
|
106
|
+
}
|
|
107
|
+
exports.encodeForSigningBatch = encodeForSigningBatch;
|
|
108
|
+
/**
|
|
109
|
+
* Encode a quality value
|
|
110
|
+
*
|
|
111
|
+
* @param value string representation of a number
|
|
112
|
+
* @returns a hex-string representing the quality
|
|
113
|
+
*/
|
|
114
|
+
function encodeQuality(value) {
|
|
115
|
+
if (typeof value !== 'string') {
|
|
116
|
+
throw new Error();
|
|
117
|
+
}
|
|
118
|
+
return (0, utils_1.bytesToHex)(coretypes_1.quality.encode(value));
|
|
119
|
+
}
|
|
120
|
+
exports.encodeQuality = encodeQuality;
|
|
121
|
+
/**
|
|
122
|
+
* Decode a quality value
|
|
123
|
+
*
|
|
124
|
+
* @param value hex-string of a quality
|
|
125
|
+
* @returns a string representing the quality
|
|
126
|
+
*/
|
|
127
|
+
function decodeQuality(value) {
|
|
128
|
+
if (typeof value !== 'string') {
|
|
129
|
+
throw new Error();
|
|
130
|
+
}
|
|
131
|
+
return coretypes_1.quality.decode(value).toString();
|
|
132
|
+
}
|
|
133
|
+
exports.decodeQuality = decodeQuality;
|
|
134
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAAA,2CAAyD;AACzD,mDAAkD;AA8JhD,iGA9JO,gCAAgB,OA8JP;AA3JlB,mCAIgB;AA0Jd,oGA7JA,2BAAmB,OA6JA;AAFnB,kGA1JA,yBAAiB,OA0JA;AAGjB,oGA5JA,2BAAmB,OA4JA;AA1JrB,+DAA0D;AAwJxD,gGAxJO,kCAAe,OAwJP;AAvJjB,mCAAmC;AA0JjC,0FA1JO,iBAAS,OA0JP;AAzJX,qDAAsD;AAEtD,MAAM,EACJ,WAAW,EACX,gBAAgB,EAChB,gBAAgB,EAChB,gBAAgB,EAChB,YAAY,EACZ,eAAe,GAChB,GAAG,kBAAM,CAAA;AAEV;;;;;;GAMG;AACH,SAAS,MAAM,CAAC,MAAc,EAAE,WAAiC;IAC/D,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE;QAC9B,MAAM,IAAI,KAAK,CAAC,6BAA6B,CAAC,CAAA;KAC/C;IACD,OAAO,YAAY,CAAC,MAAM,EAAE,WAAW,CAAC,CAAA;AAC1C,CAAC;AAqHC,wBAAM;AAnHR;;;;;;;GAOG;AACH,SAAS,MAAM,CAAC,IAAY,EAAE,WAAiC;IAC7D,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE;QAC5B,MAAM,IA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AAQ,EAAE;QAC5B,MAAM,IAAI,KAAK,CAAC,8CAA8C,CAAC,CAAA;KAChE;IACD,OAAO,IAAA,kBAAU,EAAC,gBAAgB,CAAC,IAAmB,CAAC,CAAC,CAAA;AAC1D,CAAC;AAkCC,sDAAqB;AAhCvB;;;;;GAKG;AACH,SAAS,aAAa,CAAC,KAAa;IAClC,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;QAC7B,MAAM,IAAI,KAAK,EAAE,CAAA;KAClB;IACD,OAAO,IAAA,kBAAU,EAAC,mBAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAA;AAC1C,CAAC;AAsBC,sCAAa;AApBf;;;;;GAKG;AACH,SAAS,aAAa,CAAC,KAAa;IAClC,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;QAC7B,MAAM,IAAI,KAAK,EAAE,CAAA;KAClB;IACD,OAAO,mBAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,QAAQ,EAAE,CAAA;AACzC,CAAC;AAUC,sCAAa"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { Hash256 } from './types/hash-256';
|
|
2
|
+
import { JsonObject } from './types/serialized-type';
|
|
3
|
+
import { XrplDefinitionsBase } from './enums';
|
|
4
|
+
/**
|
|
5
|
+
* Function computing the hash of a transaction tree
|
|
6
|
+
*
|
|
7
|
+
* @param param An array of transaction objects to hash
|
|
8
|
+
* @returns A Hash256 object
|
|
9
|
+
*/
|
|
10
|
+
declare function transactionTreeHash(param: Array<JsonObject>): Hash256;
|
|
11
|
+
/**
|
|
12
|
+
* Function computing the hash of accountState
|
|
13
|
+
*
|
|
14
|
+
* @param param A list of accountStates hash
|
|
15
|
+
* @returns A Hash256 object
|
|
16
|
+
*/
|
|
17
|
+
declare function accountStateHash(param: Array<JsonObject>): Hash256;
|
|
18
|
+
/**
|
|
19
|
+
* Interface describing a ledger header
|
|
20
|
+
*/
|
|
21
|
+
interface ledgerObject {
|
|
22
|
+
ledger_index: number;
|
|
23
|
+
total_coins: string | number | bigint;
|
|
24
|
+
parent_hash: string;
|
|
25
|
+
transaction_hash: string;
|
|
26
|
+
account_hash: string;
|
|
27
|
+
parent_close_time: number;
|
|
28
|
+
close_time: number;
|
|
29
|
+
close_time_resolution: number;
|
|
30
|
+
close_flags: number;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Serialize and hash a ledger header
|
|
34
|
+
*
|
|
35
|
+
* @param header a ledger header
|
|
36
|
+
* @returns the hash of header
|
|
37
|
+
*/
|
|
38
|
+
declare function ledgerHash(header: ledgerObject): Hash256;
|
|
39
|
+
/**
|
|
40
|
+
* Decodes a serialized ledger header
|
|
41
|
+
*
|
|
42
|
+
* @param binary A serialized ledger header
|
|
43
|
+
* @param definitions Type definitions to parse the ledger objects.
|
|
44
|
+
* Used if there are non-default ledger objects to decode.
|
|
45
|
+
* @returns A JSON object describing a ledger header
|
|
46
|
+
*/
|
|
47
|
+
declare function decodeLedgerData(binary: string, definitions?: XrplDefinitionsBase): object;
|
|
48
|
+
export { accountStateHash, transactionTreeHash, ledgerHash, decodeLedgerData };
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.decodeLedgerData = exports.ledgerHash = exports.transactionTreeHash = exports.accountStateHash = void 0;
|
|
4
|
+
const shamap_1 = require("./shamap");
|
|
5
|
+
const hash_prefixes_1 = require("./hash-prefixes");
|
|
6
|
+
const hashes_1 = require("./hashes");
|
|
7
|
+
const binary_1 = require("./binary");
|
|
8
|
+
const hash_256_1 = require("./types/hash-256");
|
|
9
|
+
const st_object_1 = require("./types/st-object");
|
|
10
|
+
const uint_64_1 = require("./types/uint-64");
|
|
11
|
+
const uint_32_1 = require("./types/uint-32");
|
|
12
|
+
const uint_8_1 = require("./types/uint-8");
|
|
13
|
+
const binary_parser_1 = require("./serdes/binary-parser");
|
|
14
|
+
/**
|
|
15
|
+
* Computes the hash of a list of objects
|
|
16
|
+
*
|
|
17
|
+
* @param itemizer Converts an item into a format that can be added to SHAMap
|
|
18
|
+
* @param itemsJson Array of items to add to a SHAMap
|
|
19
|
+
* @returns the hash of the SHAMap
|
|
20
|
+
*/
|
|
21
|
+
function computeHash(itemizer, itemsJson) {
|
|
22
|
+
const map = new shamap_1.ShaMap();
|
|
23
|
+
itemsJson.forEach((item) => map.addItem(...itemizer(item)));
|
|
24
|
+
return map.hash();
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Convert a transaction into an index and an item
|
|
28
|
+
*
|
|
29
|
+
* @param json transaction with metadata
|
|
30
|
+
* @returns a tuple of index and item to be added to SHAMap
|
|
31
|
+
*/
|
|
32
|
+
function transactionItemizer(json) {
|
|
33
|
+
if (!json.hash) {
|
|
34
|
+
throw new Error();
|
|
35
|
+
}
|
|
36
|
+
const index = hash_256_1.Hash256.from(json.hash);
|
|
37
|
+
const item = {
|
|
38
|
+
hashPrefix() {
|
|
39
|
+
return hash_prefixes_1.HashPrefix.transaction;
|
|
40
|
+
},
|
|
41
|
+
toBytesSink(sink) {
|
|
42
|
+
const serializer = new binary_1.BinarySerializer(sink);
|
|
43
|
+
serializer.writeLengthEncoded(st_object_1.STObject.from(json));
|
|
44
|
+
serializer.writeLengthEncoded(st_object_1.STObject.from(json.metaData));
|
|
45
|
+
},
|
|
46
|
+
};
|
|
47
|
+
return [index, item, undefined];
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Convert an entry to a pair Hash256 and ShaMapNode
|
|
51
|
+
*
|
|
52
|
+
* @param json JSON describing a ledger entry item
|
|
53
|
+
* @returns a tuple of index and item to be added to SHAMap
|
|
54
|
+
*/
|
|
55
|
+
function entryItemizer(json) {
|
|
56
|
+
const index = hash_256_1.Hash256.from(json.index);
|
|
57
|
+
const bytes = (0, binary_1.serializeObject)(json);
|
|
58
|
+
const item = {
|
|
59
|
+
hashPrefix() {
|
|
60
|
+
return hash_prefixes_1.HashPrefix.accountStateEntry;
|
|
61
|
+
},
|
|
62
|
+
toBytesSink(sink) {
|
|
63
|
+
sink.put(bytes);
|
|
64
|
+
},
|
|
65
|
+
};
|
|
66
|
+
return [index, item, undefined];
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Function computing the hash of a transaction tree
|
|
70
|
+
*
|
|
71
|
+
* @param param An array of transaction objects to hash
|
|
72
|
+
* @returns A Hash256 object
|
|
73
|
+
*/
|
|
74
|
+
function transactionTreeHash(param) {
|
|
75
|
+
const itemizer = transactionItemizer;
|
|
76
|
+
return computeHash(itemizer, param);
|
|
77
|
+
}
|
|
78
|
+
exports.transactionTreeHash = transactionTreeHash;
|
|
79
|
+
/**
|
|
80
|
+
* Function computing the hash of accountState
|
|
81
|
+
*
|
|
82
|
+
* @param param A list of accountStates hash
|
|
83
|
+
* @returns A Hash256 object
|
|
84
|
+
*/
|
|
85
|
+
function accountStateHash(param) {
|
|
86
|
+
const itemizer = entryItemizer;
|
|
87
|
+
return computeHash(itemizer, param);
|
|
88
|
+
}
|
|
89
|
+
exports.accountStateHash = accountStateHash;
|
|
90
|
+
/**
|
|
91
|
+
* Serialize and hash a ledger header
|
|
92
|
+
*
|
|
93
|
+
* @param header a ledger header
|
|
94
|
+
* @returns the hash of header
|
|
95
|
+
*/
|
|
96
|
+
function ledgerHash(header) {
|
|
97
|
+
const hash = new hashes_1.Sha512Half();
|
|
98
|
+
hash.put(hash_prefixes_1.HashPrefix.ledgerHeader);
|
|
99
|
+
if (header.parent_close_time === undefined ||
|
|
100
|
+
header.close_flags === undefined) {
|
|
101
|
+
throw new Error();
|
|
102
|
+
}
|
|
103
|
+
uint_32_1.UInt32.from(header.ledger_index).toBytesSink(hash);
|
|
104
|
+
uint_64_1.UInt64.from(BigInt(String(header.total_coins))).toBytesSink(hash);
|
|
105
|
+
hash_256_1.Hash256.from(header.parent_hash).toBytesSink(hash);
|
|
106
|
+
hash_256_1.Hash256.from(header.transaction_hash).toBytesSink(hash);
|
|
107
|
+
hash_256_1.Hash256.from(header.account_hash).toBytesSink(hash);
|
|
108
|
+
uint_32_1.UInt32.from(header.parent_close_time).toBytesSink(hash);
|
|
109
|
+
uint_32_1.UInt32.from(header.close_time).toBytesSink(hash);
|
|
110
|
+
uint_8_1.UInt8.from(header.close_time_resolution).toBytesSink(hash);
|
|
111
|
+
uint_8_1.UInt8.from(header.close_flags).toBytesSink(hash);
|
|
112
|
+
return hash.finish();
|
|
113
|
+
}
|
|
114
|
+
exports.ledgerHash = ledgerHash;
|
|
115
|
+
/**
|
|
116
|
+
* Decodes a serialized ledger header
|
|
117
|
+
*
|
|
118
|
+
* @param binary A serialized ledger header
|
|
119
|
+
* @param definitions Type definitions to parse the ledger objects.
|
|
120
|
+
* Used if there are non-default ledger objects to decode.
|
|
121
|
+
* @returns A JSON object describing a ledger header
|
|
122
|
+
*/
|
|
123
|
+
function decodeLedgerData(binary, definitions) {
|
|
124
|
+
if (typeof binary !== 'string') {
|
|
125
|
+
throw new Error('binary must be a hex string');
|
|
126
|
+
}
|
|
127
|
+
const parser = new binary_parser_1.BinaryParser(binary, definitions);
|
|
128
|
+
return {
|
|
129
|
+
ledger_index: parser.readUInt32(),
|
|
130
|
+
total_coins: parser.readType(uint_64_1.UInt64).valueOf().toString(),
|
|
131
|
+
parent_hash: parser.readType(hash_256_1.Hash256).toHex(),
|
|
132
|
+
transaction_hash: parser.readType(hash_256_1.Hash256).toHex(),
|
|
133
|
+
account_hash: parser.readType(hash_256_1.Hash256).toHex(),
|
|
134
|
+
parent_close_time: parser.readUInt32(),
|
|
135
|
+
close_time: parser.readUInt32(),
|
|
136
|
+
close_time_resolution: parser.readUInt8(),
|
|
137
|
+
close_flags: parser.readUInt8(),
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
exports.decodeLedgerData = decodeLedgerData;
|
|
141
|
+
//# sourceMappingURL=ledger-hashes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ledger-hashes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KAAK,EAAE;QAClD,YAAY,EAAE,MAAM,CAAC,QAAQ,CAAC,kBAAO,CAAC,CAAC,KAAK,EAAE;QAC9C,iBAAiB,EAAE,MAAM,CAAC,UAAU,EAAE;QACtC,UAAU,EAAE,MAAM,CAAC,UAAU,EAAE;QAC/B,qBAAqB,EAAE,MAAM,CAAC,SAAS,EAAE;QACzC,WAAW,EAAE,MAAM,CAAC,SAAS,EAAE;KAChC,CAAA;AACH,CAAC;AAE2D,4CAAgB"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import BigNumber from 'bignumber.js';
|
|
2
|
+
/**
|
|
3
|
+
* class for encoding and decoding quality
|
|
4
|
+
*/
|
|
5
|
+
declare class quality {
|
|
6
|
+
/**
|
|
7
|
+
* Encode quality amount
|
|
8
|
+
*
|
|
9
|
+
* @param arg string representation of an amount
|
|
10
|
+
* @returns Serialized quality
|
|
11
|
+
*/
|
|
12
|
+
static encode(quality: string): Uint8Array;
|
|
13
|
+
/**
|
|
14
|
+
* Decode quality amount
|
|
15
|
+
*
|
|
16
|
+
* @param arg hex-string denoting serialized quality
|
|
17
|
+
* @returns deserialized quality
|
|
18
|
+
*/
|
|
19
|
+
static decode(quality: string): BigNumber;
|
|
20
|
+
}
|
|
21
|
+
export { quality };
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.quality = void 0;
|
|
7
|
+
const types_1 = require("./types");
|
|
8
|
+
const bignumber_js_1 = __importDefault(require("bignumber.js"));
|
|
9
|
+
const utils_1 = require("@transia/isomorphic/utils");
|
|
10
|
+
/**
|
|
11
|
+
* class for encoding and decoding quality
|
|
12
|
+
*/
|
|
13
|
+
class quality {
|
|
14
|
+
/**
|
|
15
|
+
* Encode quality amount
|
|
16
|
+
*
|
|
17
|
+
* @param arg string representation of an amount
|
|
18
|
+
* @returns Serialized quality
|
|
19
|
+
*/
|
|
20
|
+
static encode(quality) {
|
|
21
|
+
const decimal = (0, bignumber_js_1.default)(quality);
|
|
22
|
+
const exponent = ((decimal === null || decimal === void 0 ? void 0 : decimal.e) || 0) - 15;
|
|
23
|
+
const qualityString = decimal.times(`1e${-exponent}`).abs().toString();
|
|
24
|
+
const bytes = types_1.coreTypes.UInt64.from(BigInt(qualityString)).toBytes();
|
|
25
|
+
bytes[0] = exponent + 100;
|
|
26
|
+
return bytes;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Decode quality amount
|
|
30
|
+
*
|
|
31
|
+
* @param arg hex-string denoting serialized quality
|
|
32
|
+
* @returns deserialized quality
|
|
33
|
+
*/
|
|
34
|
+
static decode(quality) {
|
|
35
|
+
const bytes = (0, utils_1.hexToBytes)(quality).slice(-8);
|
|
36
|
+
const exponent = bytes[0] - 100;
|
|
37
|
+
const mantissa = new bignumber_js_1.default(`0x${(0, utils_1.bytesToHex)(bytes.slice(1))}`);
|
|
38
|
+
return mantissa.times(`1e${exponent}`);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
exports.quality = quality;
|
|
42
|
+
//# sourceMappingURL=quality.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"quality.js","sourceRoot":"","sources":["../../src/quality.ts"],"names":[],"mappings":";;;;;;AAAA,mCAAmC;AACnC,gEAAoC;AACpC,qDAAkE;AAElE;;GAEG;AACH,MAAM,OAAO;IACX;;;;;OAKG;IACH,MAAM,CAAC,MAAM,CAAC,OAAe;QAC3B,MAAM,OAAO,GAAG,IAAA,sBAAS,EAAC,OAAO,CAAC,CAAA;QAClC,MAAM,QAAQ,GAAG,CAAC,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,CAAC,KAAI,CAAC,CAAC,GAAG,EAAE,CAAA;QACvC,MAAM,aAAa,GAAG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