ripple-binary-codec 1.4.0 → 1.5.0-beta.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 +985 -284
- package/dist/types/bridge.d.ts +45 -0
- package/dist/types/bridge.js +104 -0
- package/dist/types/bridge.js.map +1 -0
- package/dist/types/currency.js +1 -1
- package/dist/types/currency.js.map +1 -1
- package/dist/types/hash-160.js +1 -3
- package/dist/types/hash-160.js.map +1 -1
- package/dist/types/index.d.ts +6 -0
- package/dist/types/index.js +6 -0
- package/dist/types/index.js.map +1 -1
- package/dist/types/issued-currency.d.ts +46 -0
- package/dist/types/issued-currency.js +108 -0
- package/dist/types/issued-currency.js.map +1 -0
- package/dist/types/sidechain.d.ts +45 -0
- package/dist/types/sidechain.js +104 -0
- package/dist/types/sidechain.js.map +1 -0
- package/dist/types/signature.d.ts +39 -0
- package/dist/types/signature.js +125 -0
- package/dist/types/signature.js.map +1 -0
- package/dist/types/st-object.js +3 -0
- package/dist/types/st-object.js.map +1 -1
- package/dist/types/xchain-attestation-batch.d.ts +44 -0
- package/dist/types/xchain-attestation-batch.js +107 -0
- package/dist/types/xchain-attestation-batch.js.map +1 -0
- package/dist/types/xchain-bridge.d.ts +45 -0
- package/dist/types/xchain-bridge.js +119 -0
- package/dist/types/xchain-bridge.js.map +1 -0
- package/dist/types/xchain-claim-proof.d.ts +55 -0
- package/dist/types/xchain-claim-proof.js +115 -0
- package/dist/types/xchain-claim-proof.js.map +1 -0
- package/package.json +5 -5
- package/test/fixtures/codec-fixtures.json +261 -14
- package/test/fixtures/data-driven-tests.json +0 -14
- package/test/hash.test.js +11 -7
- package/test/signing-data-encoding.test.js +11 -0
|
@@ -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 { IssuedCurrencyObject } from './issued-currency';
|
|
5
|
+
/**
|
|
6
|
+
* Interface for JSON objects that represent bridges
|
|
7
|
+
*/
|
|
8
|
+
interface BridgeObject extends JsonObject {
|
|
9
|
+
dst_chain_door: string;
|
|
10
|
+
dst_chain_issue: IssuedCurrencyObject | string;
|
|
11
|
+
src_chain_door: string;
|
|
12
|
+
src_chain_issue: IssuedCurrencyObject | string;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Class for serializing/deserializing Bridges
|
|
16
|
+
*/
|
|
17
|
+
declare class Bridge extends SerializedType {
|
|
18
|
+
static readonly ZERO_Bridge: Bridge;
|
|
19
|
+
static readonly TYPE_ORDER: {
|
|
20
|
+
name: string;
|
|
21
|
+
type: typeof SerializedType;
|
|
22
|
+
}[];
|
|
23
|
+
constructor(bytes: Buffer);
|
|
24
|
+
/**
|
|
25
|
+
* Construct a bridge from a JSON
|
|
26
|
+
*
|
|
27
|
+
* @param value Bridge or JSON to parse into a Bridge
|
|
28
|
+
* @returns A Bridge object
|
|
29
|
+
*/
|
|
30
|
+
static from<T extends Bridge | BridgeObject>(value: T): Bridge;
|
|
31
|
+
/**
|
|
32
|
+
* Read a Bridge from a BinaryParser
|
|
33
|
+
*
|
|
34
|
+
* @param parser BinaryParser to read the Bridge from
|
|
35
|
+
* @returns A Bridge object
|
|
36
|
+
*/
|
|
37
|
+
static fromParser(parser: BinaryParser): Bridge;
|
|
38
|
+
/**
|
|
39
|
+
* Get the JSON representation of this Bridge
|
|
40
|
+
*
|
|
41
|
+
* @returns the JSON interpretation of this.bytes
|
|
42
|
+
*/
|
|
43
|
+
toJSON(): BridgeObject;
|
|
44
|
+
}
|
|
45
|
+
export { Bridge, BridgeObject };
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
if (typeof b !== "function" && b !== null)
|
|
11
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
+
extendStatics(d, b);
|
|
13
|
+
function __() { this.constructor = d; }
|
|
14
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
+
};
|
|
16
|
+
})();
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.Bridge = void 0;
|
|
19
|
+
var binary_parser_1 = require("../serdes/binary-parser");
|
|
20
|
+
var account_id_1 = require("./account-id");
|
|
21
|
+
var serialized_type_1 = require("./serialized-type");
|
|
22
|
+
var buffer_1 = require("buffer/");
|
|
23
|
+
var issued_currency_1 = require("./issued-currency");
|
|
24
|
+
/**
|
|
25
|
+
* Type guard for BridgeObject
|
|
26
|
+
*/
|
|
27
|
+
function isBridgeObject(arg) {
|
|
28
|
+
var keys = Object.keys(arg).sort();
|
|
29
|
+
return (keys.length === 4 &&
|
|
30
|
+
keys[0] === 'dst_chain_door' &&
|
|
31
|
+
keys[1] === 'dst_chain_issue' &&
|
|
32
|
+
keys[2] === 'src_chain_door' &&
|
|
33
|
+
keys[3] === 'src_chain_issue');
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Class for serializing/deserializing Bridges
|
|
37
|
+
*/
|
|
38
|
+
var Bridge = /** @class */ (function (_super) {
|
|
39
|
+
__extends(Bridge, _super);
|
|
40
|
+
function Bridge(bytes) {
|
|
41
|
+
return _super.call(this, bytes !== null && bytes !== void 0 ? bytes : Bridge.ZERO_Bridge.bytes) || this;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Construct a bridge from a JSON
|
|
45
|
+
*
|
|
46
|
+
* @param value Bridge or JSON to parse into a Bridge
|
|
47
|
+
* @returns A Bridge object
|
|
48
|
+
*/
|
|
49
|
+
Bridge.from = function (value) {
|
|
50
|
+
if (value instanceof Bridge) {
|
|
51
|
+
return value;
|
|
52
|
+
}
|
|
53
|
+
if (isBridgeObject(value)) {
|
|
54
|
+
var bytes_1 = [];
|
|
55
|
+
this.TYPE_ORDER.forEach(function (item) {
|
|
56
|
+
var name = item.name, type = item.type;
|
|
57
|
+
var object = type.from(value[name]);
|
|
58
|
+
bytes_1.push(object.toBytes());
|
|
59
|
+
});
|
|
60
|
+
return new Bridge(buffer_1.Buffer.concat(bytes_1));
|
|
61
|
+
}
|
|
62
|
+
throw new Error('Invalid type to construct a Bridge');
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
65
|
+
* Read a Bridge from a BinaryParser
|
|
66
|
+
*
|
|
67
|
+
* @param parser BinaryParser to read the Bridge from
|
|
68
|
+
* @returns A Bridge object
|
|
69
|
+
*/
|
|
70
|
+
Bridge.fromParser = function (parser) {
|
|
71
|
+
var bytes = [];
|
|
72
|
+
this.TYPE_ORDER.forEach(function (item) {
|
|
73
|
+
var type = item.type;
|
|
74
|
+
var object = type.fromParser(parser);
|
|
75
|
+
bytes.push(object.toBytes());
|
|
76
|
+
});
|
|
77
|
+
return new Bridge(buffer_1.Buffer.concat(bytes));
|
|
78
|
+
};
|
|
79
|
+
/**
|
|
80
|
+
* Get the JSON representation of this Bridge
|
|
81
|
+
*
|
|
82
|
+
* @returns the JSON interpretation of this.bytes
|
|
83
|
+
*/
|
|
84
|
+
Bridge.prototype.toJSON = function () {
|
|
85
|
+
var parser = new binary_parser_1.BinaryParser(this.toString());
|
|
86
|
+
var json = {};
|
|
87
|
+
Bridge.TYPE_ORDER.forEach(function (item) {
|
|
88
|
+
var name = item.name, type = item.type;
|
|
89
|
+
var object = type.fromParser(parser).toJSON();
|
|
90
|
+
json[name] = object;
|
|
91
|
+
});
|
|
92
|
+
return json;
|
|
93
|
+
};
|
|
94
|
+
Bridge.ZERO_Bridge = new Bridge(buffer_1.Buffer.alloc(80));
|
|
95
|
+
Bridge.TYPE_ORDER = [
|
|
96
|
+
{ name: 'src_chain_door', type: account_id_1.AccountID },
|
|
97
|
+
{ name: 'src_chain_issue', type: issued_currency_1.IssuedCurrency },
|
|
98
|
+
{ name: 'dst_chain_door', type: account_id_1.AccountID },
|
|
99
|
+
{ name: 'dst_chain_issue', type: issued_currency_1.IssuedCurrency },
|
|
100
|
+
];
|
|
101
|
+
return Bridge;
|
|
102
|
+
}(serialized_type_1.SerializedType));
|
|
103
|
+
exports.Bridge = Bridge;
|
|
104
|
+
//# sourceMappingURL=bridge.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bridge.js","sourceRoot":"","sources":["../../src/types/bridge.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA,yDAAsD;AAEtD,2CAAwC;AACxC,qDAA8D;AAC9D,kCAAgC;AAChC,qDAAwE;AAYxE;;GAEG;AACH,SAAS,cAAc,CAAC,GAAG;IACzB,IAAM,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,gBAAgB;QAC5B,IAAI,CAAC,CAAC,CAAC,KAAK,iBAAiB;QAC7B,IAAI,CAAC,CAAC,CAAC,KAAK,gBAAgB;QAC5B,IAAI,CAAC,CAAC,CAAC,KAAK,iBAAiB,CAC9B,CAAA;AACH,CAAC;AAED;;GAEG;AACH;IAAqB,0BAAc;IAWjC,gBAAY,KAAa;eACvB,kBAAM,KAAK,aAAL,KAAK,cAAL,KAAK,GAAI,MAAM,CAAC,WAAW,CAAC,KAAK,CAAC;IAC1C,CAAC;IAED;;;;;OAKG;IACI,WAAI,GAAX,UAA6C,KAAQ;QACnD,IAAI,KAAK,YAAY,MAAM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AAf,EAAE,IAAI,GAAK,IAAI,KAAT,CAAS;YAC3B,IAAM,MAAM,GAAG,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,CAAA;YAC/C,IAAI,CAAC,IAAI,CAAC,GAAG,MAAM,CAAA;QACrB,CAAC,CAAC,CAAA;QACF,OAAO,IAAoB,CAAA;IAC7B,CAAC;IAtEe,kBAAW,GAAW,IAAI,MAAM,CAAC,eAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAA;IAElD,iBAAU,GACxB;QACE,EAAE,IAAI,EAAE,gBAAgB,EAAE,IAAI,EAAE,sBAAS,EAAE;QAC3C,EAAE,IAAI,EAAE,iBAAiB,EAAE,IAAI,EAAE,gCAAc,EAAE;QACjD,EAAE,IAAI,EAAE,gBAAgB,EAAE,IAAI,EAAE,sBAAS,EAAE;QAC3C,EAAE,IAAI,EAAE,iBAAiB,EAAE,IAAI,EAAE,gCAAc,EAAE;KAClD,CAAA;IA+DL,aAAC;CAAA,AAxED,CAAqB,gCAAc,GAwElC;AAEQ,wBAAM"}
|
package/dist/types/currency.js
CHANGED
|
@@ -19,7 +19,7 @@ exports.Currency = void 0;
|
|
|
19
19
|
var hash_160_1 = require("./hash-160");
|
|
20
20
|
var buffer_1 = require("buffer/");
|
|
21
21
|
var XRP_HEX_REGEX = /^0{40}$/;
|
|
22
|
-
var ISO_REGEX = /^[A-Z0-
|
|
22
|
+
var ISO_REGEX = /^[A-Z0-9a-z?!@#$%^&*(){}[\]|]{3}$/;
|
|
23
23
|
var HEX_REGEX = /^[A-F0-9]{40}$/;
|
|
24
24
|
// eslint-disable-next-line no-control-regex
|
|
25
25
|
var STANDARD_FORMAT_HEX_REGEX = /^0{24}[\x00-\x7F]{6}0{10}$/;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"currency.js","sourceRoot":"","sources":["../../src/types/currency.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA,uCAAoC;AACp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,KAAK,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,CAAA;SACrD;aAAM;YACL,KAAI,CAAC,IAAI,GAAG,IAAI,CAAA;SACjB;;IACH,CAAC;IAED;;;;OAIG;IACH,sBAAG,GAAH;QACE,OAAO,IAAI,CAAC,IAAI,CAAA;IAClB,CAAC;IAED;;;;OAIG;IACI,aAAI,GAAX,UAAwC,KAAQ;QAC9C,IAAI,KAAK,YAAY,QAAQ,EAAE;YAC7B,OAAO,KAAK,CAAA;SACb;QAED,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;YAC7B,OAAO,IAAI,QAAQ,CAAC,uBAAuB,CAAC,KAAK,CAAC,CAAC,CAAA;SACpD;QAED,MAAM,IAAI,KAAK,CAAC,4CAA4C,CAAC,CAAA;IAC/D,CAAC;IAED;;;;OAIG;IACH,yBAAM,GAAN;QACE,IAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAA;QACtB,IAAI,GAAG,KAAK,IAAI,EAAE;YAChB,OAAO,GAAG,CAAA;SACX;QACD,OAAO,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,WAAW,EAAE,CAAA;IACjD,CAAC;IArDe,YAAG,GAAG,IAAI,QAAQ,CAAC,eAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAA;IAsDtD,eAAC;CAAA,AAvDD,CAAuB,kBAAO,GAuD7B;AAEQ,4BAAQ"}
|
package/dist/types/hash-160.js
CHANGED
|
@@ -24,12 +24,10 @@ var buffer_1 = require("buffer/");
|
|
|
24
24
|
var Hash160 = /** @class */ (function (_super) {
|
|
25
25
|
__extends(Hash160, _super);
|
|
26
26
|
function Hash160(bytes) {
|
|
27
|
-
var _this = this;
|
|
28
27
|
if (bytes && bytes.byteLength === 0) {
|
|
29
28
|
bytes = Hash160.ZERO_160.bytes;
|
|
30
29
|
}
|
|
31
|
-
|
|
32
|
-
return _this;
|
|
30
|
+
return _super.call(this, bytes !== null && bytes !== void 0 ? bytes : Hash160.ZERO_160.bytes) || this;
|
|
33
31
|
}
|
|
34
32
|
Hash160.width = 20;
|
|
35
33
|
Hash160.ZERO_160 = new Hash160(buffer_1.Buffer.alloc(Hash160.width));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hash-160.js","sourceRoot":"","sources":["../../src/types/hash-160.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA,+BAA6B;AAC7B,kCAAgC;AAEhC;;GAEG;AACH;IAAsB,2BAAI;IAIxB,iBAAY,KAAc;
|
|
1
|
+
{"version":3,"file":"hash-160.js","sourceRoot":"","sources":["../../src/types/hash-160.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA,+BAA6B;AAC7B,kCAAgC;AAEhC;;GAEG;AACH;IAAsB,2BAAI;IAIxB,iBAAY,KAAc;QACxB,IAAI,KAAK,IAAI,KAAK,CAAC,UAAU,KAAK,CAAC,EAAE;YACnC,KAAK,GAAG,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAA;SAC/B;eAED,kBAAM,KAAK,aAAL,KAAK,cAAL,KAAK,GAAI,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC;IACxC,CAAC;IATe,aAAK,GAAG,EAAE,CAAA;IACV,gBAAQ,GAAY,IAAI,OAAO,CAAC,eAAM,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAA;IAS9E,cAAC;CAAA,AAXD,CAAsB,WAAI,GAWzB;AAEQ,0BAAO"}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ import { Currency } from './currency';
|
|
|
5
5
|
import { Hash128 } from './hash-128';
|
|
6
6
|
import { Hash160 } from './hash-160';
|
|
7
7
|
import { Hash256 } from './hash-256';
|
|
8
|
+
import { IssuedCurrency } from './issued-currency';
|
|
8
9
|
import { PathSet } from './path-set';
|
|
9
10
|
import { STArray } from './st-array';
|
|
10
11
|
import { STObject } from './st-object';
|
|
@@ -13,6 +14,8 @@ import { UInt32 } from './uint-32';
|
|
|
13
14
|
import { UInt64 } from './uint-64';
|
|
14
15
|
import { UInt8 } from './uint-8';
|
|
15
16
|
import { Vector256 } from './vector-256';
|
|
17
|
+
import { XChainAttestationBatch } from './xchain-attestation-batch';
|
|
18
|
+
import { XChainBridge } from './xchain-bridge';
|
|
16
19
|
declare const coreTypes: {
|
|
17
20
|
AccountID: typeof AccountID;
|
|
18
21
|
Amount: typeof Amount;
|
|
@@ -21,6 +24,7 @@ declare const coreTypes: {
|
|
|
21
24
|
Hash128: typeof Hash128;
|
|
22
25
|
Hash160: typeof Hash160;
|
|
23
26
|
Hash256: typeof Hash256;
|
|
27
|
+
IssuedCurrency: typeof IssuedCurrency;
|
|
24
28
|
PathSet: typeof PathSet;
|
|
25
29
|
STArray: typeof STArray;
|
|
26
30
|
STObject: typeof STObject;
|
|
@@ -29,5 +33,7 @@ declare const coreTypes: {
|
|
|
29
33
|
UInt32: typeof UInt32;
|
|
30
34
|
UInt64: typeof UInt64;
|
|
31
35
|
Vector256: typeof Vector256;
|
|
36
|
+
XChainAttestationBatch: typeof XChainAttestationBatch;
|
|
37
|
+
XChainBridge: typeof XChainBridge;
|
|
32
38
|
};
|
|
33
39
|
export { coreTypes };
|
package/dist/types/index.js
CHANGED
|
@@ -9,6 +9,7 @@ var currency_1 = require("./currency");
|
|
|
9
9
|
var hash_128_1 = require("./hash-128");
|
|
10
10
|
var hash_160_1 = require("./hash-160");
|
|
11
11
|
var hash_256_1 = require("./hash-256");
|
|
12
|
+
var issued_currency_1 = require("./issued-currency");
|
|
12
13
|
var path_set_1 = require("./path-set");
|
|
13
14
|
var st_array_1 = require("./st-array");
|
|
14
15
|
var st_object_1 = require("./st-object");
|
|
@@ -17,6 +18,8 @@ var uint_32_1 = require("./uint-32");
|
|
|
17
18
|
var uint_64_1 = require("./uint-64");
|
|
18
19
|
var uint_8_1 = require("./uint-8");
|
|
19
20
|
var vector_256_1 = require("./vector-256");
|
|
21
|
+
var xchain_attestation_batch_1 = require("./xchain-attestation-batch");
|
|
22
|
+
var xchain_bridge_1 = require("./xchain-bridge");
|
|
20
23
|
var coreTypes = {
|
|
21
24
|
AccountID: account_id_1.AccountID,
|
|
22
25
|
Amount: amount_1.Amount,
|
|
@@ -25,6 +28,7 @@ var coreTypes = {
|
|
|
25
28
|
Hash128: hash_128_1.Hash128,
|
|
26
29
|
Hash160: hash_160_1.Hash160,
|
|
27
30
|
Hash256: hash_256_1.Hash256,
|
|
31
|
+
IssuedCurrency: issued_currency_1.IssuedCurrency,
|
|
28
32
|
PathSet: path_set_1.PathSet,
|
|
29
33
|
STArray: st_array_1.STArray,
|
|
30
34
|
STObject: st_object_1.STObject,
|
|
@@ -33,6 +37,8 @@ var coreTypes = {
|
|
|
33
37
|
UInt32: uint_32_1.UInt32,
|
|
34
38
|
UInt64: uint_64_1.UInt64,
|
|
35
39
|
Vector256: vector_256_1.Vector256,
|
|
40
|
+
XChainAttestationBatch: xchain_attestation_batch_1.XChainAttestationBatch,
|
|
41
|
+
XChainBridge: xchain_bridge_1.XChainBridge,
|
|
36
42
|
};
|
|
37
43
|
exports.coreTypes = coreTypes;
|
|
38
44
|
Object.values(enums_1.Field).forEach(function (field) {
|
package/dist/types/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":";;;AAAA,kCAKiB;AACjB,2CAAwC;AACxC,mCAAiC;AACjC,+BAA6B;AAC7B,uCAAqC;AACrC,uCAAoC;AACpC,uCAAoC;AACpC,uCAAoC;AACpC,uCAAoC;AACpC,uCAAoC;AACpC,yCAAsC;AACtC,qCAAkC;AAClC,qCAAkC;AAClC,qCAAkC;AAClC,mCAAgC;AAChC,2CAAwC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":";;;AAAA,kCAKiB;AACjB,2CAAwC;AACxC,mCAAiC;AACjC,+BAA6B;AAC7B,uCAAqC;AACrC,uCAAoC;AACpC,uCAAoC;AACpC,uCAAoC;AACpC,qDAAkD;AAClD,uCAAoC;AACpC,uCAAoC;AACpC,yCAAsC;AACtC,qCAAkC;AAClC,qCAAkC;AAClC,qCAAkC;AAClC,mCAAgC;AAChC,2CAAwC;AACxC,uEAAmE;AACnE,iDAA8C;AAE9C,IAAM,SAAS,GAAG;IAChB,SAAS,wBAAA;IACT,MAAM,iBAAA;IACN,IAAI,aAAA;IACJ,QAAQ,qBAAA;IACR,OAAO,oBAAA;IACP,OAAO,oBAAA;IACP,OAAO,oBAAA;IACP,cAAc,kCAAA;IACd,OAAO,oBAAA;IACP,OAAO,oBAAA;IACP,QAAQ,sBAAA;IACR,KAAK,gBAAA;IACL,MAAM,kBAAA;IACN,MAAM,kBAAA;IACN,MAAM,kBAAA;IACN,SAAS,wBAAA;IACT,sBAAsB,mDAAA;IACtB,YAAY,8BAAA;CACb,CAAA;AAUQ,8BAAS;AARlB,MAAM,CAAC,MAAM,CAAC,aAAK,CAAC,CAAC,OAAO,CAAC,UAAC,KAAK;IACjC,KAAK,CAAC,cAAc,GAAG,SAAS,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;AACnD,CAAC,CAAC,CAAA;AAEF,aAAK,CAAC,iBAAiB,CAAC,CAAC,cAAc,GAAG,uBAAe,CAAA;AACzD,aAAK,CAAC,mBAAmB,CAAC,CAAC,cAAc,GAAG,yBAAiB,CAAA;AAC7D,aAAK,CAAC,iBAAiB,CAAC,CAAC,cAAc,GAAG,uBAAe,CAAA"}
|
|
@@ -0,0 +1,46 @@
|
|
|
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 IssuedCurrencyObject extends JsonObject {
|
|
8
|
+
currency: string;
|
|
9
|
+
issuer: string;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Class for serializing/Deserializing Amounts
|
|
13
|
+
*/
|
|
14
|
+
declare class IssuedCurrency extends SerializedType {
|
|
15
|
+
static readonly ZERO_ISSUED_CURRENCY: IssuedCurrency;
|
|
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 IssuedCurrency | IssuedCurrencyObject | string>(value: T): IssuedCurrency;
|
|
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): IssuedCurrency;
|
|
32
|
+
/**
|
|
33
|
+
* Get the JSON representation of this Amount
|
|
34
|
+
*
|
|
35
|
+
* @returns the JSON interpretation of this.bytes
|
|
36
|
+
*/
|
|
37
|
+
toJSON(): IssuedCurrencyObject | string;
|
|
38
|
+
/**
|
|
39
|
+
* Validate XRP amount
|
|
40
|
+
*
|
|
41
|
+
* @param value String representing XRP amount
|
|
42
|
+
* @returns void, but will throw if invalid amount
|
|
43
|
+
*/
|
|
44
|
+
private static assertXrpIsValid;
|
|
45
|
+
}
|
|
46
|
+
export { IssuedCurrency, IssuedCurrencyObject };
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
if (typeof b !== "function" && b !== null)
|
|
11
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
+
extendStatics(d, b);
|
|
13
|
+
function __() { this.constructor = d; }
|
|
14
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
+
};
|
|
16
|
+
})();
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.IssuedCurrency = void 0;
|
|
19
|
+
var binary_parser_1 = require("../serdes/binary-parser");
|
|
20
|
+
var account_id_1 = require("./account-id");
|
|
21
|
+
var currency_1 = require("./currency");
|
|
22
|
+
var serialized_type_1 = require("./serialized-type");
|
|
23
|
+
var buffer_1 = require("buffer/");
|
|
24
|
+
/**
|
|
25
|
+
* Type guard for AmountObject
|
|
26
|
+
*/
|
|
27
|
+
function isIssuedCurrencyObject(arg) {
|
|
28
|
+
var keys = Object.keys(arg).sort();
|
|
29
|
+
return keys.length === 2 && keys[0] === 'currency' && keys[1] === 'issuer';
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Class for serializing/Deserializing Amounts
|
|
33
|
+
*/
|
|
34
|
+
var IssuedCurrency = /** @class */ (function (_super) {
|
|
35
|
+
__extends(IssuedCurrency, _super);
|
|
36
|
+
function IssuedCurrency(bytes) {
|
|
37
|
+
return _super.call(this, bytes !== null && bytes !== void 0 ? bytes : IssuedCurrency.ZERO_ISSUED_CURRENCY.bytes) || this;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Construct an amount from an IOU or string amount
|
|
41
|
+
*
|
|
42
|
+
* @param value An Amount, object representing an IOU, or a string
|
|
43
|
+
* representing an integer amount
|
|
44
|
+
* @returns An Amount object
|
|
45
|
+
*/
|
|
46
|
+
IssuedCurrency.from = function (value) {
|
|
47
|
+
if (value instanceof IssuedCurrency) {
|
|
48
|
+
return value;
|
|
49
|
+
}
|
|
50
|
+
if (typeof value === 'string') {
|
|
51
|
+
IssuedCurrency.assertXrpIsValid(value);
|
|
52
|
+
var currency = currency_1.Currency.from(value).toBytes();
|
|
53
|
+
return new IssuedCurrency(currency);
|
|
54
|
+
}
|
|
55
|
+
if (isIssuedCurrencyObject(value)) {
|
|
56
|
+
var currency = currency_1.Currency.from(value.currency).toBytes();
|
|
57
|
+
var issuer = account_id_1.AccountID.from(value.issuer).toBytes();
|
|
58
|
+
return new IssuedCurrency(buffer_1.Buffer.concat([currency, issuer]));
|
|
59
|
+
}
|
|
60
|
+
throw new Error('Invalid type to construct an Amount');
|
|
61
|
+
};
|
|
62
|
+
/**
|
|
63
|
+
* Read an amount from a BinaryParser
|
|
64
|
+
*
|
|
65
|
+
* @param parser BinaryParser to read the Amount from
|
|
66
|
+
* @returns An Amount object
|
|
67
|
+
*/
|
|
68
|
+
IssuedCurrency.fromParser = function (parser) {
|
|
69
|
+
var currency = parser.read(20);
|
|
70
|
+
if (new currency_1.Currency(currency).toJSON() === 'XRP') {
|
|
71
|
+
return new IssuedCurrency(currency);
|
|
72
|
+
}
|
|
73
|
+
var currencyAndIssuer = [currency, parser.read(20)];
|
|
74
|
+
return new IssuedCurrency(buffer_1.Buffer.concat(currencyAndIssuer));
|
|
75
|
+
};
|
|
76
|
+
/**
|
|
77
|
+
* Get the JSON representation of this Amount
|
|
78
|
+
*
|
|
79
|
+
* @returns the JSON interpretation of this.bytes
|
|
80
|
+
*/
|
|
81
|
+
IssuedCurrency.prototype.toJSON = function () {
|
|
82
|
+
var parser = new binary_parser_1.BinaryParser(this.toString());
|
|
83
|
+
var currency = currency_1.Currency.fromParser(parser);
|
|
84
|
+
if (currency.toJSON() === 'XRP') {
|
|
85
|
+
return currency.toJSON();
|
|
86
|
+
}
|
|
87
|
+
var issuer = account_id_1.AccountID.fromParser(parser);
|
|
88
|
+
return {
|
|
89
|
+
currency: currency.toJSON(),
|
|
90
|
+
issuer: issuer.toJSON(),
|
|
91
|
+
};
|
|
92
|
+
};
|
|
93
|
+
/**
|
|
94
|
+
* Validate XRP amount
|
|
95
|
+
*
|
|
96
|
+
* @param value String representing XRP amount
|
|
97
|
+
* @returns void, but will throw if invalid amount
|
|
98
|
+
*/
|
|
99
|
+
IssuedCurrency.assertXrpIsValid = function (value) {
|
|
100
|
+
if (value !== 'XRP') {
|
|
101
|
+
throw new Error("".concat(value, " is an illegal amount"));
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
IssuedCurrency.ZERO_ISSUED_CURRENCY = new IssuedCurrency(buffer_1.Buffer.alloc(20));
|
|
105
|
+
return IssuedCurrency;
|
|
106
|
+
}(serialized_type_1.SerializedType));
|
|
107
|
+
exports.IssuedCurrency = IssuedCurrency;
|
|
108
|
+
//# sourceMappingURL=issued-currency.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"issued-currency.js","sourceRoot":"","sources":["../../src/types/issued-currency.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA,yDAAsD;AAEtD,2CAAwC;AACxC,uCAAqC;AACrC,qDAA8D;AAC9D,kCAAgC;AAUhC;;GAEG;AACH,SAAS,sBAAsB,CAAC,GAAG;IACjC,IAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,CAAA;IACpC,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;IAA6B,kCAAc;IAKzC,wBAAY,KAAa;eACvB,kBAAM,KAAK,aAAL,KAAK,cAAL,KAAK,GAAI,cAAc,CAAC,oBAAoB,CAAC,KAAK,CAAC;IAC3D,CAAC;IAED;;;;;;OAMG;IACI,mBAAI,GAAX,UACE,KA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CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAA;QAChD,IAAM,QAAQ,GAAG,mBAAQ,CAAC,UAAU,CAAC,MAAM,CAAa,CAAA;QACxD,IAAI,QAAQ,CAAC,MAAM,EAAE,KAAK,KAAK,EAAE;YAC/B,OAAO,QAAQ,CAAC,MAAM,EAAE,CAAA;SACzB;QACD,IAAM,MAAM,GAAG,sBAAS,CAAC,UAAU,CAAC,MAAM,CAAc,CAAA;QAExD,OAAO;YACL,QAAQ,EAAE,QAAQ,CAAC,MAAM,EAAE;YAC3B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE;SACxB,CAAA;IACH,CAAC;IAED;;;;;OAKG;IACY,+BAAgB,GAA/B,UAAgC,KAAa;QAC3C,IAAI,KAAK,KAAK,KAAK,EAAE;YACnB,MAAM,IAAI,KAAK,CAAC,UAAG,KAAK,0BAAuB,CAAC,CAAA;SACjD;IACH,CAAC;IAnFe,mCAAoB,GAAmB,IAAI,cAAc,CACvE,eAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CACjB,CAAA;IAkFH,qBAAC;CAAA,AArFD,CAA6B,gCAAc,GAqF1C;AAEQ,wCAAc"}
|
|
@@ -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 { IssuedCurrencyObject } from './issued-currency';
|
|
5
|
+
/**
|
|
6
|
+
* Interface for JSON objects that represent sidechains
|
|
7
|
+
*/
|
|
8
|
+
interface SidechainObject extends JsonObject {
|
|
9
|
+
dst_chain_door: string;
|
|
10
|
+
dst_chain_issue: IssuedCurrencyObject | string;
|
|
11
|
+
src_chain_door: string;
|
|
12
|
+
src_chain_issue: IssuedCurrencyObject | string;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Class for serializing/deserializing Sidechains
|
|
16
|
+
*/
|
|
17
|
+
declare class Sidechain extends SerializedType {
|
|
18
|
+
static readonly ZERO_SIDECHAIN: Sidechain;
|
|
19
|
+
static readonly TYPE_ORDER: {
|
|
20
|
+
name: string;
|
|
21
|
+
type: typeof SerializedType;
|
|
22
|
+
}[];
|
|
23
|
+
constructor(bytes: Buffer);
|
|
24
|
+
/**
|
|
25
|
+
* Construct a sidechain from a JSON
|
|
26
|
+
*
|
|
27
|
+
* @param value Sidechain or JSON to parse into a Sidechain
|
|
28
|
+
* @returns A Sidechain object
|
|
29
|
+
*/
|
|
30
|
+
static from<T extends Sidechain | SidechainObject>(value: T): Sidechain;
|
|
31
|
+
/**
|
|
32
|
+
* Read a Sidechain from a BinaryParser
|
|
33
|
+
*
|
|
34
|
+
* @param parser BinaryParser to read the Sidechain from
|
|
35
|
+
* @returns A Sidechain object
|
|
36
|
+
*/
|
|
37
|
+
static fromParser(parser: BinaryParser): Sidechain;
|
|
38
|
+
/**
|
|
39
|
+
* Get the JSON representation of this Sidechain
|
|
40
|
+
*
|
|
41
|
+
* @returns the JSON interpretation of this.bytes
|
|
42
|
+
*/
|
|
43
|
+
toJSON(): SidechainObject;
|
|
44
|
+
}
|
|
45
|
+
export { Sidechain, SidechainObject };
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
if (typeof b !== "function" && b !== null)
|
|
11
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
+
extendStatics(d, b);
|
|
13
|
+
function __() { this.constructor = d; }
|
|
14
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
+
};
|
|
16
|
+
})();
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.Sidechain = void 0;
|
|
19
|
+
var binary_parser_1 = require("../serdes/binary-parser");
|
|
20
|
+
var account_id_1 = require("./account-id");
|
|
21
|
+
var serialized_type_1 = require("./serialized-type");
|
|
22
|
+
var buffer_1 = require("buffer/");
|
|
23
|
+
var issued_currency_1 = require("./issued-currency");
|
|
24
|
+
/**
|
|
25
|
+
* Type guard for SidechainObject
|
|
26
|
+
*/
|
|
27
|
+
function isSidechainObject(arg) {
|
|
28
|
+
var keys = Object.keys(arg).sort();
|
|
29
|
+
return (keys.length === 4 &&
|
|
30
|
+
keys[0] === 'dst_chain_door' &&
|
|
31
|
+
keys[1] === 'dst_chain_issue' &&
|
|
32
|
+
keys[2] === 'src_chain_door' &&
|
|
33
|
+
keys[3] === 'src_chain_issue');
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Class for serializing/deserializing Sidechains
|
|
37
|
+
*/
|
|
38
|
+
var Sidechain = /** @class */ (function (_super) {
|
|
39
|
+
__extends(Sidechain, _super);
|
|
40
|
+
function Sidechain(bytes) {
|
|
41
|
+
return _super.call(this, bytes !== null && bytes !== void 0 ? bytes : Sidechain.ZERO_SIDECHAIN.bytes) || this;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Construct a sidechain from a JSON
|
|
45
|
+
*
|
|
46
|
+
* @param value Sidechain or JSON to parse into a Sidechain
|
|
47
|
+
* @returns A Sidechain object
|
|
48
|
+
*/
|
|
49
|
+
Sidechain.from = function (value) {
|
|
50
|
+
if (value instanceof Sidechain) {
|
|
51
|
+
return value;
|
|
52
|
+
}
|
|
53
|
+
if (isSidechainObject(value)) {
|
|
54
|
+
var bytes_1 = [];
|
|
55
|
+
this.TYPE_ORDER.forEach(function (item) {
|
|
56
|
+
var name = item.name, type = item.type;
|
|
57
|
+
var object = type.from(value[name]);
|
|
58
|
+
bytes_1.push(object.toBytes());
|
|
59
|
+
});
|
|
60
|
+
return new Sidechain(buffer_1.Buffer.concat(bytes_1));
|
|
61
|
+
}
|
|
62
|
+
throw new Error('Invalid type to construct a Sidechain');
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
65
|
+
* Read a Sidechain from a BinaryParser
|
|
66
|
+
*
|
|
67
|
+
* @param parser BinaryParser to read the Sidechain from
|
|
68
|
+
* @returns A Sidechain object
|
|
69
|
+
*/
|
|
70
|
+
Sidechain.fromParser = function (parser) {
|
|
71
|
+
var bytes = [];
|
|
72
|
+
this.TYPE_ORDER.forEach(function (item) {
|
|
73
|
+
var type = item.type;
|
|
74
|
+
var object = type.fromParser(parser);
|
|
75
|
+
bytes.push(object.toBytes());
|
|
76
|
+
});
|
|
77
|
+
return new Sidechain(buffer_1.Buffer.concat(bytes));
|
|
78
|
+
};
|
|
79
|
+
/**
|
|
80
|
+
* Get the JSON representation of this Sidechain
|
|
81
|
+
*
|
|
82
|
+
* @returns the JSON interpretation of this.bytes
|
|
83
|
+
*/
|
|
84
|
+
Sidechain.prototype.toJSON = function () {
|
|
85
|
+
var parser = new binary_parser_1.BinaryParser(this.toString());
|
|
86
|
+
var json = {};
|
|
87
|
+
Sidechain.TYPE_ORDER.forEach(function (item) {
|
|
88
|
+
var name = item.name, type = item.type;
|
|
89
|
+
var object = type.fromParser(parser).toJSON();
|
|
90
|
+
json[name] = object;
|
|
91
|
+
});
|
|
92
|
+
return json;
|
|
93
|
+
};
|
|
94
|
+
Sidechain.ZERO_SIDECHAIN = new Sidechain(buffer_1.Buffer.alloc(80));
|
|
95
|
+
Sidechain.TYPE_ORDER = [
|
|
96
|
+
{ name: 'src_chain_door', type: account_id_1.AccountID },
|
|
97
|
+
{ name: 'src_chain_issue', type: issued_currency_1.IssuedCurrency },
|
|
98
|
+
{ name: 'dst_chain_door', type: account_id_1.AccountID },
|
|
99
|
+
{ name: 'dst_chain_issue', type: issued_currency_1.IssuedCurrency },
|
|
100
|
+
];
|
|
101
|
+
return Sidechain;
|
|
102
|
+
}(serialized_type_1.SerializedType));
|
|
103
|
+
exports.Sidechain = Sidechain;
|
|
104
|
+
//# sourceMappingURL=sidechain.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sidechain.js","sourceRoot":"","sources":["../../src/types/sidechain.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA,yDAAsD;AAEtD,2CAAwC;AACxC,qDAA8D;AAC9D,kCAAgC;AAChC,qDAAwE;AAYxE;;GAEG;AACH,SAAS,iBAAiB,CAAC,GAAG;IAC5B,IAAM,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,gBAAgB;QAC5B,IAAI,CAAC,CAAC,CAAC,KAAK,iBAAiB;QAC7B,IAAI,CAAC,CAAC,CAAC,KAAK,gBAAgB;QAC5B,IAAI,CAAC,CAAC,CAAC,KAAK,iBAAiB,CAC9B,CAAA;AACH,CAAC;AAED;;GAEG;AACH;IAAwB,6BAAc;IAWpC,mBAAY,KAAa;eACvB,kBAAM,KAAK,aAAL,KAAK,cAAL,KAAK,GAAI,SAAS,CAAC,cAAc,CAAC,KAAK,CAAC;IAChD,CAAC;IAED;;;;;OAKG;IACI,cAAI,GAAX,UAAmD,KAAQ;QACzD,IAAI,KAAK,YAAY,SAAS,EAAE;YAC9B,OAAO,KAAK,CAAA;SACb;QAED,IAAI,iBAAiB,CAAC,KAAK,CAAC,EAAE;YAC5B,IAAM,OAAK,GAAkB,EAAE,CAAA;YAC/B,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,UAAC,IAAI;gBACnB,IAAA,IAAI,GAAW,IAAI,KAAf,EAAE,IAAI,GAAK,IAAI,KAAT,CAAS;gBAC3B,IAAM,M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IAAI,SAAS,CAAC,eAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAA;IAE3D,oBAAU,GACxB;QACE,EAAE,IAAI,EAAE,gBAAgB,EAAE,IAAI,EAAE,sBAAS,EAAE;QAC3C,EAAE,IAAI,EAAE,iBAAiB,EAAE,IAAI,EAAE,gCAAc,EAAE;QACjD,EAAE,IAAI,EAAE,gBAAgB,EAAE,IAAI,EAAE,sBAAS,EAAE;QAC3C,EAAE,IAAI,EAAE,iBAAiB,EAAE,IAAI,EAAE,gCAAc,EAAE;KAClD,CAAA;IA+DL,gBAAC;CAAA,AAxED,CAAwB,gCAAc,GAwErC;AAEQ,8BAAS"}
|
|
@@ -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 SignatureObject extends JsonObject {
|
|
8
|
+
signature: string;
|
|
9
|
+
signing_key: string;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Class for serializing/Deserializing Amounts
|
|
13
|
+
*/
|
|
14
|
+
declare class Signature extends SerializedType {
|
|
15
|
+
static readonly ZERO_SIGNATURE: Signature;
|
|
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 Signature | SignatureObject>(value: T): Signature;
|
|
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): Signature;
|
|
32
|
+
/**
|
|
33
|
+
* Get the JSON representation of this Amount
|
|
34
|
+
*
|
|
35
|
+
* @returns the JSON interpretation of this.bytes
|
|
36
|
+
*/
|
|
37
|
+
toJSON(): SignatureObject;
|
|
38
|
+
}
|
|
39
|
+
export { Signature, SignatureObject };
|