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.
- package/dist/enums/definitions.json +250 -1
- package/dist/enums/src/enums/definitions.json +250 -1
- package/dist/types/index.js +2 -0
- package/dist/types/index.js.map +1 -1
- 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/xchain-bridge.d.ts +45 -0
- package/dist/types/xchain-bridge.js +102 -0
- package/dist/types/xchain-bridge.js.map +1 -0
- package/package.json +3 -4
- package/src/README.md +3 -0
- package/src/binary.ts +188 -0
- package/src/coretypes.ts +31 -0
- package/src/enums/README.md +144 -0
- package/src/enums/bytes.ts +75 -0
- package/src/enums/constants.ts +4 -0
- package/src/enums/definitions.json +2599 -0
- package/src/enums/field.ts +85 -0
- package/src/enums/index.ts +34 -0
- package/src/enums/utils-renumber.ts +134 -0
- package/src/enums/xrpl-definitions-base.ts +111 -0
- package/src/enums/xrpl-definitions.ts +32 -0
- package/src/hash-prefixes.ts +40 -0
- package/src/hashes.ts +76 -0
- package/src/index.ts +141 -0
- package/src/ledger-hashes.ts +187 -0
- package/src/quality.ts +39 -0
- package/src/serdes/binary-parser.ts +217 -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 +256 -0
- package/src/types/blob.ts +43 -0
- package/src/types/currency.ts +140 -0
- package/src/types/hash-128.ts +33 -0
- package/src/types/hash-160.ts +20 -0
- package/src/types/hash-256.ts +16 -0
- package/src/types/hash.ts +81 -0
- package/src/types/index.ts +61 -0
- package/src/types/issue.ts +96 -0
- package/src/types/path-set.ts +290 -0
- package/src/types/serialized-type.ts +120 -0
- package/src/types/st-array.ts +107 -0
- package/src/types/st-object.ts +192 -0
- package/src/types/uint-16.ts +49 -0
- package/src/types/uint-32.ts +56 -0
- package/src/types/uint-64.ts +105 -0
- package/src/types/uint-8.ts +49 -0
- package/src/types/uint.ts +57 -0
- package/src/types/vector-256.ts +84 -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 -289
- package/test/definitions.test.js +0 -160
- 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/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/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 -242
- 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
package/dist/types/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":";;;AAAA,6CAAwC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":";;;AAAA,6CAAwC;AA6CtC,0FA7CO,sBAAS,OA6CP;AA5CX,qCAAiC;AA6C/B,uFA7CO,eAAM,OA6CP;AA5CR,iCAA6B;AA6C3B,qFA7CO,WAAI,OA6CP;AA5CN,yCAAqC;AA6CnC,yFA7CO,mBAAQ,OA6CP;AA5CV,yCAAoC;AA6ClC,wFA7CO,kBAAO,OA6CP;AA5CT,yCAAoC;AA6ClC,wFA7CO,kBAAO,OA6CP;AA5CT,yCAAoC;AA6ClC,wFA7CO,kBAAO,OA6CP;AA5CT,mCAA+B;AAC/B,yCAAoC;AA4ClC,wFA5CO,kBAAO,OA4CP;AA3CT,yCAAoC;AA4ClC,wFA5CO,kBAAO,OA4CP;AA3CT,2CAAsC;AA4CpC,yFA5CO,oBAAQ,OA4CP;AA3CV,uCAAkC;AA6ChC,uFA7CO,gBAAM,OA6CP;AA5CR,uCAAkC;AA6ChC,uFA7CO,gBAAM,OA6CP;AA5CR,uCAAkC;AA6ChC,uFA7CO,gBAAM,OA6CP;AA5CR,qCAAgC;AAyC9B,sFAzCO,cAAK,OAyCP;AAxCP,6CAAwC;AA4CtC,0FA5CO,sBAAS,OA4CP;AA1CX,oCAA8C;AAE9C,MAAM,SAAS,GAA0C;IACvD,SAAS,EAAT,sBAAS;IACT,MAAM,EAAN,eAAM;IACN,IAAI,EAAJ,WAAI;IACJ,QAAQ,EAAR,mBAAQ;IACR,OAAO,EAAP,kBAAO;IACP,OAAO,EAAP,kBAAO;IACP,OAAO,EAAP,kBAAO;IACP,KAAK,EAAL,aAAK;IACL,OAAO,EAAP,kBAAO;IACP,OAAO,EAAP,kBAAO;IACP,QAAQ,EAAR,oBAAQ;IACR,KAAK,EAAL,cAAK;IACL,MAAM,EAAN,gBAAM;IACN,MAAM,EAAN,gBAAM;IACN,MAAM,EAAN,gBAAM;IACN,SAAS,EAAT,sBAAS;CACV,CAAA;AAQC,8BAAS;AANX,2GAA2G;AAC3G,gFAAgF;AAChF,8FAA8F;AAC9F,2BAAmB,CAAC,cAAc,CAAC,SAAS,CAAC,CAAA"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { BinaryParser } from '../serdes/binary-parser';
|
|
2
|
+
import { JsonObject, SerializedType } from './serialized-type';
|
|
3
|
+
import { Buffer } from 'buffer/';
|
|
4
|
+
/**
|
|
5
|
+
* Interface for JSON objects that represent amounts
|
|
6
|
+
*/
|
|
7
|
+
interface IssueObject extends JsonObject {
|
|
8
|
+
currency: string;
|
|
9
|
+
issuer?: string;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Class for serializing/Deserializing Amounts
|
|
13
|
+
*/
|
|
14
|
+
declare class Issue extends SerializedType {
|
|
15
|
+
static readonly ZERO_ISSUED_CURRENCY: Issue;
|
|
16
|
+
constructor(bytes: Buffer);
|
|
17
|
+
/**
|
|
18
|
+
* Construct an amount from an IOU or string amount
|
|
19
|
+
*
|
|
20
|
+
* @param value An Amount, object representing an IOU, or a string
|
|
21
|
+
* representing an integer amount
|
|
22
|
+
* @returns An Amount object
|
|
23
|
+
*/
|
|
24
|
+
static from<T extends Issue | IssueObject>(value: T): Issue;
|
|
25
|
+
/**
|
|
26
|
+
* Read an amount from a BinaryParser
|
|
27
|
+
*
|
|
28
|
+
* @param parser BinaryParser to read the Amount from
|
|
29
|
+
* @returns An Amount object
|
|
30
|
+
*/
|
|
31
|
+
static fromParser(parser: BinaryParser): Issue;
|
|
32
|
+
/**
|
|
33
|
+
* Get the JSON representation of this Amount
|
|
34
|
+
*
|
|
35
|
+
* @returns the JSON interpretation of this.bytes
|
|
36
|
+
*/
|
|
37
|
+
toJSON(): IssueObject;
|
|
38
|
+
}
|
|
39
|
+
export { Issue, IssueObject };
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Issue = void 0;
|
|
4
|
+
const binary_parser_1 = require("../serdes/binary-parser");
|
|
5
|
+
const account_id_1 = require("./account-id");
|
|
6
|
+
const currency_1 = require("./currency");
|
|
7
|
+
const serialized_type_1 = require("./serialized-type");
|
|
8
|
+
const buffer_1 = require("buffer/");
|
|
9
|
+
/**
|
|
10
|
+
* Type guard for AmountObject
|
|
11
|
+
*/
|
|
12
|
+
function isIssueObject(arg) {
|
|
13
|
+
const keys = Object.keys(arg).sort();
|
|
14
|
+
if (keys.length === 1) {
|
|
15
|
+
return keys[0] === 'currency';
|
|
16
|
+
}
|
|
17
|
+
return keys.length === 2 && keys[0] === 'currency' && keys[1] === 'issuer';
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Class for serializing/Deserializing Amounts
|
|
21
|
+
*/
|
|
22
|
+
class Issue extends serialized_type_1.SerializedType {
|
|
23
|
+
constructor(bytes) {
|
|
24
|
+
super(bytes !== null && bytes !== void 0 ? bytes : Issue.ZERO_ISSUED_CURRENCY.bytes);
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Construct an amount from an IOU or string amount
|
|
28
|
+
*
|
|
29
|
+
* @param value An Amount, object representing an IOU, or a string
|
|
30
|
+
* representing an integer amount
|
|
31
|
+
* @returns An Amount object
|
|
32
|
+
*/
|
|
33
|
+
static from(value) {
|
|
34
|
+
if (value instanceof Issue) {
|
|
35
|
+
return value;
|
|
36
|
+
}
|
|
37
|
+
if (isIssueObject(value)) {
|
|
38
|
+
const currency = currency_1.Currency.from(value.currency).toBytes();
|
|
39
|
+
if (value.issuer == null) {
|
|
40
|
+
return new Issue(currency);
|
|
41
|
+
}
|
|
42
|
+
const issuer = account_id_1.AccountID.from(value.issuer).toBytes();
|
|
43
|
+
return new Issue(buffer_1.Buffer.concat([currency, issuer]));
|
|
44
|
+
}
|
|
45
|
+
throw new Error('Invalid type to construct an Amount');
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Read an amount from a BinaryParser
|
|
49
|
+
*
|
|
50
|
+
* @param parser BinaryParser to read the Amount from
|
|
51
|
+
* @returns An Amount object
|
|
52
|
+
*/
|
|
53
|
+
static fromParser(parser) {
|
|
54
|
+
const currency = parser.read(20);
|
|
55
|
+
if (new currency_1.Currency(currency).toJSON() === 'XRP') {
|
|
56
|
+
return new Issue(currency);
|
|
57
|
+
}
|
|
58
|
+
const currencyAndIssuer = [currency, parser.read(20)];
|
|
59
|
+
return new Issue(buffer_1.Buffer.concat(currencyAndIssuer));
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Get the JSON representation of this Amount
|
|
63
|
+
*
|
|
64
|
+
* @returns the JSON interpretation of this.bytes
|
|
65
|
+
*/
|
|
66
|
+
toJSON() {
|
|
67
|
+
const parser = new binary_parser_1.BinaryParser(this.toString());
|
|
68
|
+
const currency = currency_1.Currency.fromParser(parser);
|
|
69
|
+
if (currency.toJSON() === 'XRP') {
|
|
70
|
+
return { currency: currency.toJSON() };
|
|
71
|
+
}
|
|
72
|
+
const issuer = account_id_1.AccountID.fromParser(parser);
|
|
73
|
+
return {
|
|
74
|
+
currency: currency.toJSON(),
|
|
75
|
+
issuer: issuer.toJSON(),
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
exports.Issue = Issue;
|
|
80
|
+
Issue.ZERO_ISSUED_CURRENCY = new Issue(buffer_1.Buffer.alloc(20));
|
|
81
|
+
//# sourceMappingURL=issue.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"issue.js","sourceRoot":"","sources":["../../src/types/issue.ts"],"names":[],"mappings":";;;AAAA,2DAAsD;AAEtD,6CAAwC;AACxC,yCAAqC;AACrC,uDAA8D;AAC9D,oCAAgC;AAUhC;;GAEG;AACH,SAAS,aAAa,CAAC,GAAG;IACxB,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,CAAA;IACpC,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE;QACrB,OAAO,IAAI,CAAC,CAAC,CAAC,KAAK,UAAU,CAAA;KAC9B;IACD,OAAO,IAAI,CAAC,MAAM,KAAK,CAAC,IAAI,IAAI,CAAC,CAAC,CAAC,KAAK,UAAU,IAAI,IAAI,CAAC,CAAC,CAAC,KAAK,QAAQ,CAAA;AAC5E,CAAC;AAED;;GAEG;AACH,MAAM,KAAM,SAAQ,gCAAc;IAGhC,YAAY,KAAa;QACvB,KAAK,CAAC,KAAK,aAAL,KAAK,cAAL,KAAK,GAAI,KAAK,CAAC,oBAAoB,CAAC,KAAK,CAAC,CAAA;IAClD,CAAC;IAED;;;;;;OAMG;IACH,MAAM,CAAC,IAAI,CAAgC,KAAQ;QACjD,IAAI,KAAK,YAAY,KAAK,EAAE;YAC1B,OAAO,KAAK,CAAA;SACb;QAED,IAAI,aAAa,CAAC,KAAK,CAAC,EAAE;YACxB,MAAM,QAAQ,GAAG,mBAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,OAAO,EAAE,CAAA;YACxD,IAAI,KAAK,CAAC,MAAM,IAAI,IAAI,EAAE;gBACxB,OAAO,IAAI,KAAK,CAAC,QAAQ,CAAC,CAAA;aAC3B;YACD,MAAM,MAAM,GAAG,sBAAS,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,C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C,CAAA"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { BinaryParser } from '../serdes/binary-parser';
|
|
2
|
+
import { JsonObject, SerializedType } from './serialized-type';
|
|
3
|
+
import { Buffer } from 'buffer/';
|
|
4
|
+
import { IssueObject } from './issue';
|
|
5
|
+
/**
|
|
6
|
+
* Interface for JSON objects that represent cross-chain bridges
|
|
7
|
+
*/
|
|
8
|
+
interface XChainBridgeObject extends JsonObject {
|
|
9
|
+
LockingChainDoor: string;
|
|
10
|
+
LockingChainIssue: IssueObject | string;
|
|
11
|
+
IssuingChainDoor: string;
|
|
12
|
+
IssuingChainIssue: IssueObject | string;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Class for serializing/deserializing XChainBridges
|
|
16
|
+
*/
|
|
17
|
+
declare class XChainBridge extends SerializedType {
|
|
18
|
+
static readonly ZERO_XCHAIN_BRIDGE: XChainBridge;
|
|
19
|
+
static readonly TYPE_ORDER: {
|
|
20
|
+
name: string;
|
|
21
|
+
type: typeof SerializedType;
|
|
22
|
+
}[];
|
|
23
|
+
constructor(bytes: Buffer);
|
|
24
|
+
/**
|
|
25
|
+
* Construct a cross-chain bridge from a JSON
|
|
26
|
+
*
|
|
27
|
+
* @param value XChainBridge or JSON to parse into a XChainBridge
|
|
28
|
+
* @returns A XChainBridge object
|
|
29
|
+
*/
|
|
30
|
+
static from<T extends XChainBridge | XChainBridgeObject>(value: T): XChainBridge;
|
|
31
|
+
/**
|
|
32
|
+
* Read a XChainBridge from a BinaryParser
|
|
33
|
+
*
|
|
34
|
+
* @param parser BinaryParser to read the XChainBridge from
|
|
35
|
+
* @returns A XChainBridge object
|
|
36
|
+
*/
|
|
37
|
+
static fromParser(parser: BinaryParser): XChainBridge;
|
|
38
|
+
/**
|
|
39
|
+
* Get the JSON representation of this XChainBridge
|
|
40
|
+
*
|
|
41
|
+
* @returns the JSON interpretation of this.bytes
|
|
42
|
+
*/
|
|
43
|
+
toJSON(): XChainBridgeObject;
|
|
44
|
+
}
|
|
45
|
+
export { XChainBridge, XChainBridgeObject };
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.XChainBridge = void 0;
|
|
4
|
+
const binary_parser_1 = require("../serdes/binary-parser");
|
|
5
|
+
const account_id_1 = require("./account-id");
|
|
6
|
+
const serialized_type_1 = require("./serialized-type");
|
|
7
|
+
const buffer_1 = require("buffer/");
|
|
8
|
+
const issue_1 = require("./issue");
|
|
9
|
+
/**
|
|
10
|
+
* Type guard for XChainBridgeObject
|
|
11
|
+
*/
|
|
12
|
+
function isXChainBridgeObject(arg) {
|
|
13
|
+
const keys = Object.keys(arg).sort();
|
|
14
|
+
return (keys.length === 4 &&
|
|
15
|
+
keys[0] === 'IssuingChainDoor' &&
|
|
16
|
+
keys[1] === 'IssuingChainIssue' &&
|
|
17
|
+
keys[2] === 'LockingChainDoor' &&
|
|
18
|
+
keys[3] === 'LockingChainIssue');
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Class for serializing/deserializing XChainBridges
|
|
22
|
+
*/
|
|
23
|
+
class XChainBridge extends serialized_type_1.SerializedType {
|
|
24
|
+
constructor(bytes) {
|
|
25
|
+
super(bytes !== null && bytes !== void 0 ? bytes : XChainBridge.ZERO_XCHAIN_BRIDGE.bytes);
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Construct a cross-chain bridge from a JSON
|
|
29
|
+
*
|
|
30
|
+
* @param value XChainBridge or JSON to parse into a XChainBridge
|
|
31
|
+
* @returns A XChainBridge object
|
|
32
|
+
*/
|
|
33
|
+
static from(value) {
|
|
34
|
+
if (value instanceof XChainBridge) {
|
|
35
|
+
return value;
|
|
36
|
+
}
|
|
37
|
+
if (isXChainBridgeObject(value)) {
|
|
38
|
+
const bytes = [];
|
|
39
|
+
this.TYPE_ORDER.forEach((item) => {
|
|
40
|
+
const { name, type } = item;
|
|
41
|
+
if (type === account_id_1.AccountID) {
|
|
42
|
+
bytes.push(buffer_1.Buffer.from([0x14]));
|
|
43
|
+
}
|
|
44
|
+
const object = type.from(value[name]);
|
|
45
|
+
bytes.push(object.toBytes());
|
|
46
|
+
});
|
|
47
|
+
return new XChainBridge(buffer_1.Buffer.concat(bytes));
|
|
48
|
+
}
|
|
49
|
+
throw new Error('Invalid type to construct a XChainBridge');
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Read a XChainBridge from a BinaryParser
|
|
53
|
+
*
|
|
54
|
+
* @param parser BinaryParser to read the XChainBridge from
|
|
55
|
+
* @returns A XChainBridge object
|
|
56
|
+
*/
|
|
57
|
+
static fromParser(parser) {
|
|
58
|
+
const bytes = [];
|
|
59
|
+
this.TYPE_ORDER.forEach((item) => {
|
|
60
|
+
const { type } = item;
|
|
61
|
+
if (type === account_id_1.AccountID) {
|
|
62
|
+
parser.skip(1);
|
|
63
|
+
bytes.push(buffer_1.Buffer.from([0x14]));
|
|
64
|
+
}
|
|
65
|
+
const object = type.fromParser(parser);
|
|
66
|
+
bytes.push(object.toBytes());
|
|
67
|
+
});
|
|
68
|
+
return new XChainBridge(buffer_1.Buffer.concat(bytes));
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Get the JSON representation of this XChainBridge
|
|
72
|
+
*
|
|
73
|
+
* @returns the JSON interpretation of this.bytes
|
|
74
|
+
*/
|
|
75
|
+
toJSON() {
|
|
76
|
+
const parser = new binary_parser_1.BinaryParser(this.toString());
|
|
77
|
+
const json = {};
|
|
78
|
+
XChainBridge.TYPE_ORDER.forEach((item) => {
|
|
79
|
+
const { name, type } = item;
|
|
80
|
+
if (type === account_id_1.AccountID) {
|
|
81
|
+
parser.skip(1);
|
|
82
|
+
}
|
|
83
|
+
const object = type.fromParser(parser).toJSON();
|
|
84
|
+
json[name] = object;
|
|
85
|
+
});
|
|
86
|
+
return json;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
exports.XChainBridge = XChainBridge;
|
|
90
|
+
XChainBridge.ZERO_XCHAIN_BRIDGE = new XChainBridge(buffer_1.Buffer.concat([
|
|
91
|
+
buffer_1.Buffer.from([0x14]),
|
|
92
|
+
buffer_1.Buffer.alloc(40),
|
|
93
|
+
buffer_1.Buffer.from([0x14]),
|
|
94
|
+
buffer_1.Buffer.alloc(40),
|
|
95
|
+
]));
|
|
96
|
+
XChainBridge.TYPE_ORDER = [
|
|
97
|
+
{ name: 'LockingChainDoor', type: account_id_1.AccountID },
|
|
98
|
+
{ name: 'LockingChainIssue', type: issue_1.Issue },
|
|
99
|
+
{ name: 'IssuingChainDoor', type: account_id_1.AccountID },
|
|
100
|
+
{ name: 'IssuingChainIssue', type: issue_1.Issue },
|
|
101
|
+
];
|
|
102
|
+
//# sourceMappingURL=xchain-bridge.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"xchain-bridge.js","sourceRoot":"","sources":["../../src/types/xchain-bridge.ts"],"names":[],"mappings":";;;AAAA,2DAAsD;AAEtD,6CAAwC;AACxC,uDAA8D;AAC9D,oCAAgC;AAChC,mCAA4C;AAY5C;;GAEG;AACH,SAAS,oBAAoB,CAAC,GAAG;IAC/B,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,CAAA;IACpC,OAAO,CACL,IAAI,CAAC,MAAM,KAAK,CAAC;QACjB,IAAI,CAAC,CAAC,CAAC,KAAK,kBAAkB;QAC9B,IAAI,CAAC,CAAC,CAAC,KAAK,mBAAmB;QAC/B,IAAI,CAAC,CAAC,CAAC,KAAK,kBAAkB;QAC9B,IAAI,CAAC,CAAC,CAAC,KAAK,mBAAmB,CAChC,CAAA;AACH,CAAC;AAED;;GAEG;AACH,MAAM,YAAa,SAAQ,gCAAc;IAkBvC,YAAY,KAAa;QACvB,KAAK,CAAC,KAAK,aAAL,KAAK,cAAL,KAAK,GAAI,YAAY,CAAC,kBAAkB,CAAC,KA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EAAE,kBAAkB,EAAE,IAAI,EAAE,sBAAS,EAAE;IAC7C,EAAE,IAAI,EAAE,mBAAmB,EAAE,IAAI,EAAE,aAAK,EAAE;CAC3C,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ripple-binary-codec",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.9.0",
|
|
4
4
|
"description": "XRP Ledger binary codec",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist/*",
|
|
7
|
-
"
|
|
8
|
-
"test/*"
|
|
7
|
+
"src/*"
|
|
9
8
|
],
|
|
10
9
|
"main": "dist/",
|
|
11
10
|
"directories": {
|
|
@@ -40,5 +39,5 @@
|
|
|
40
39
|
"engines": {
|
|
41
40
|
"node": ">= 10"
|
|
42
41
|
},
|
|
43
|
-
"gitHead": "
|
|
42
|
+
"gitHead": "37fbc03584f4671317576a97ad2cdb3f6c1e1bed"
|
|
44
43
|
}
|
package/src/README.md
ADDED
package/src/binary.ts
ADDED
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
/* eslint-disable func-style */
|
|
2
|
+
|
|
3
|
+
import { coreTypes } from './types'
|
|
4
|
+
import { BinaryParser } from './serdes/binary-parser'
|
|
5
|
+
import { AccountID } from './types/account-id'
|
|
6
|
+
import { HashPrefix } from './hash-prefixes'
|
|
7
|
+
import { BinarySerializer, BytesList } from './serdes/binary-serializer'
|
|
8
|
+
import { sha512Half, transactionID } from './hashes'
|
|
9
|
+
import {
|
|
10
|
+
type XrplDefinitionsBase,
|
|
11
|
+
DEFAULT_DEFINITIONS,
|
|
12
|
+
type FieldInstance,
|
|
13
|
+
} from './enums'
|
|
14
|
+
import { STObject } from './types/st-object'
|
|
15
|
+
import { JsonObject } from './types/serialized-type'
|
|
16
|
+
import { Buffer } from 'buffer/'
|
|
17
|
+
import bigInt = require('big-integer')
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Construct a BinaryParser
|
|
21
|
+
*
|
|
22
|
+
* @param bytes hex-string to construct BinaryParser from
|
|
23
|
+
* @param definitions rippled definitions used to parse the values of transaction types and such.
|
|
24
|
+
* Can be customized for sidechains and amendments.
|
|
25
|
+
* @returns A BinaryParser
|
|
26
|
+
*/
|
|
27
|
+
const makeParser = (
|
|
28
|
+
bytes: string,
|
|
29
|
+
definitions?: XrplDefinitionsBase,
|
|
30
|
+
): BinaryParser => new BinaryParser(bytes, definitions)
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Parse BinaryParser into JSON
|
|
34
|
+
*
|
|
35
|
+
* @param parser BinaryParser object
|
|
36
|
+
* @param definitions rippled definitions used to parse the values of transaction types and such.
|
|
37
|
+
* Can be customized for sidechains and amendments.
|
|
38
|
+
* @returns JSON for the bytes in the BinaryParser
|
|
39
|
+
*/
|
|
40
|
+
const readJSON = (
|
|
41
|
+
parser: BinaryParser,
|
|
42
|
+
definitions: XrplDefinitionsBase = DEFAULT_DEFINITIONS,
|
|
43
|
+
): JsonObject =>
|
|
44
|
+
(parser.readType(coreTypes.STObject) as STObject).toJSON(definitions)
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Parse a hex-string into its JSON interpretation
|
|
48
|
+
*
|
|
49
|
+
* @param bytes hex-string to parse into JSON
|
|
50
|
+
* @param definitions rippled definitions used to parse the values of transaction types and such.
|
|
51
|
+
* Can be customized for sidechains and amendments.
|
|
52
|
+
* @returns JSON
|
|
53
|
+
*/
|
|
54
|
+
const binaryToJSON = (
|
|
55
|
+
bytes: string,
|
|
56
|
+
definitions?: XrplDefinitionsBase,
|
|
57
|
+
): JsonObject => readJSON(makeParser(bytes, definitions), definitions)
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Interface for passing parameters to SerializeObject
|
|
61
|
+
*
|
|
62
|
+
* @field set signingFieldOnly to true if you want to serialize only signing fields
|
|
63
|
+
*/
|
|
64
|
+
interface OptionObject {
|
|
65
|
+
prefix?: Buffer
|
|
66
|
+
suffix?: Buffer
|
|
67
|
+
signingFieldsOnly?: boolean
|
|
68
|
+
definitions?: XrplDefinitionsBase
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Function to serialize JSON object representing a transaction
|
|
73
|
+
*
|
|
74
|
+
* @param object JSON object to serialize
|
|
75
|
+
* @param opts options for serializing, including optional prefix, suffix, signingFieldOnly, and definitions
|
|
76
|
+
* @returns A Buffer containing the serialized object
|
|
77
|
+
*/
|
|
78
|
+
function serializeObject(object: JsonObject, opts: OptionObject = {}): Buffer {
|
|
79
|
+
const { prefix, suffix, signingFieldsOnly = false, definitions } = opts
|
|
80
|
+
const bytesList = new BytesList()
|
|
81
|
+
|
|
82
|
+
if (prefix) {
|
|
83
|
+
bytesList.put(prefix)
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const filter = signingFieldsOnly
|
|
87
|
+
? (f: FieldInstance): boolean => f.isSigningField
|
|
88
|
+
: undefined
|
|
89
|
+
;(coreTypes.STObject as typeof STObject)
|
|
90
|
+
.from(object, filter, definitions)
|
|
91
|
+
.toBytesSink(bytesList)
|
|
92
|
+
|
|
93
|
+
if (suffix) {
|
|
94
|
+
bytesList.put(suffix)
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
return bytesList.toBytes()
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Serialize an object for signing
|
|
102
|
+
*
|
|
103
|
+
* @param transaction Transaction to serialize
|
|
104
|
+
* @param prefix Prefix bytes to put before the serialized object
|
|
105
|
+
* @param opts.definitions Custom rippled types to use instead of the default. Used for sidechains and amendments.
|
|
106
|
+
* @returns A Buffer with the serialized object
|
|
107
|
+
*/
|
|
108
|
+
function signingData(
|
|
109
|
+
transaction: JsonObject,
|
|
110
|
+
prefix: Buffer = HashPrefix.transactionSig,
|
|
111
|
+
opts: { definitions?: XrplDefinitionsBase } = {},
|
|
112
|
+
): Buffer {
|
|
113
|
+
return serializeObject(transaction, {
|
|
114
|
+
prefix,
|
|
115
|
+
signingFieldsOnly: true,
|
|
116
|
+
definitions: opts.definitions,
|
|
117
|
+
})
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Interface describing fields required for a Claim
|
|
122
|
+
*/
|
|
123
|
+
interface ClaimObject extends JsonObject {
|
|
124
|
+
channel: string
|
|
125
|
+
amount: string | number
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Serialize a signingClaim
|
|
130
|
+
*
|
|
131
|
+
* @param claim A claim object to serialize
|
|
132
|
+
* @param opts.definitions Custom rippled types to use instead of the default. Used for sidechains and amendments.
|
|
133
|
+
* @returns the serialized object with appropriate prefix
|
|
134
|
+
*/
|
|
135
|
+
function signingClaimData(claim: ClaimObject): Buffer {
|
|
136
|
+
const num = bigInt(String(claim.amount))
|
|
137
|
+
const prefix = HashPrefix.paymentChannelClaim
|
|
138
|
+
const channel = coreTypes.Hash256.from(claim.channel).toBytes()
|
|
139
|
+
const amount = coreTypes.UInt64.from(num).toBytes()
|
|
140
|
+
|
|
141
|
+
const bytesList = new BytesList()
|
|
142
|
+
|
|
143
|
+
bytesList.put(prefix)
|
|
144
|
+
bytesList.put(channel)
|
|
145
|
+
bytesList.put(amount)
|
|
146
|
+
return bytesList.toBytes()
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Serialize a transaction object for multiSigning
|
|
151
|
+
*
|
|
152
|
+
* @param transaction transaction to serialize
|
|
153
|
+
* @param signingAccount Account to sign the transaction with
|
|
154
|
+
* @param opts.definitions Custom rippled types to use instead of the default. Used for sidechains and amendments.
|
|
155
|
+
* @returns serialized transaction with appropriate prefix and suffix
|
|
156
|
+
*/
|
|
157
|
+
function multiSigningData(
|
|
158
|
+
transaction: JsonObject,
|
|
159
|
+
signingAccount: string | AccountID,
|
|
160
|
+
opts: { definitions: XrplDefinitionsBase } = {
|
|
161
|
+
definitions: DEFAULT_DEFINITIONS,
|
|
162
|
+
},
|
|
163
|
+
): Buffer {
|
|
164
|
+
const prefix = HashPrefix.transactionMultiSig
|
|
165
|
+
const suffix = coreTypes.AccountID.from(signingAccount).toBytes()
|
|
166
|
+
return serializeObject(transaction, {
|
|
167
|
+
prefix,
|
|
168
|
+
suffix,
|
|
169
|
+
signingFieldsOnly: true,
|
|
170
|
+
definitions: opts.definitions,
|
|
171
|
+
})
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
export {
|
|
175
|
+
BinaryParser,
|
|
176
|
+
BinarySerializer,
|
|
177
|
+
BytesList,
|
|
178
|
+
ClaimObject,
|
|
179
|
+
makeParser,
|
|
180
|
+
serializeObject,
|
|
181
|
+
readJSON,
|
|
182
|
+
multiSigningData,
|
|
183
|
+
signingData,
|
|
184
|
+
signingClaimData,
|
|
185
|
+
binaryToJSON,
|
|
186
|
+
sha512Half,
|
|
187
|
+
transactionID,
|
|
188
|
+
}
|
package/src/coretypes.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import {
|
|
2
|
+
DEFAULT_DEFINITIONS,
|
|
3
|
+
Field,
|
|
4
|
+
TransactionType,
|
|
5
|
+
LedgerEntryType,
|
|
6
|
+
Type,
|
|
7
|
+
TransactionResult,
|
|
8
|
+
} from './enums'
|
|
9
|
+
import * as types from './types'
|
|
10
|
+
import * as binary from './binary'
|
|
11
|
+
import { ShaMap } from './shamap'
|
|
12
|
+
import * as ledgerHashes from './ledger-hashes'
|
|
13
|
+
import * as hashes from './hashes'
|
|
14
|
+
import { quality } from './quality'
|
|
15
|
+
import { HashPrefix } from './hash-prefixes'
|
|
16
|
+
|
|
17
|
+
export {
|
|
18
|
+
hashes,
|
|
19
|
+
binary,
|
|
20
|
+
ledgerHashes,
|
|
21
|
+
DEFAULT_DEFINITIONS,
|
|
22
|
+
Field,
|
|
23
|
+
TransactionType,
|
|
24
|
+
LedgerEntryType,
|
|
25
|
+
Type,
|
|
26
|
+
TransactionResult,
|
|
27
|
+
quality,
|
|
28
|
+
HashPrefix,
|
|
29
|
+
ShaMap,
|
|
30
|
+
types,
|
|
31
|
+
}
|