API typed as object (#94)

encode, encode for signing, and decode ledger are all typed as `object`. linter error disabled.
This commit is contained in:
Nathan Nichols
2020-08-18 13:33:23 -05:00
parent d136a4e4a8
commit d3064920f1
4 changed files with 25 additions and 16 deletions

View File

@@ -28,9 +28,11 @@ function decode(binary: string): JsonObject {
* @param json The JSON representation of a transaction
* @returns A hex-string of the encoded transaction
*/
function encode(json: JsonObject): string {
function encode(json: object): string {
assert(typeof json === "object");
return serializeObject(json).toString("hex").toUpperCase();
return serializeObject(json as JsonObject)
.toString("hex")
.toUpperCase();
}
/**
@@ -40,9 +42,11 @@ function encode(json: JsonObject): string {
* @param signer string representing the account to sign the transaction with
* @returns a hex string of the encoded transaction
*/
function encodeForSigning(json: JsonObject): string {
function encodeForSigning(json: object): string {
assert(typeof json === "object");
return signingData(json).toString("hex").toUpperCase();
return signingData(json as JsonObject)
.toString("hex")
.toUpperCase();
}
/**
@@ -52,9 +56,11 @@ function encodeForSigning(json: JsonObject): string {
* @param signer string representing the account to sign the transaction with
* @returns a hex string of the encoded transaction
*/
function encodeForSigningClaim(json: ClaimObject): string {
function encodeForSigningClaim(json: object): string {
assert(typeof json === "object");
return signingClaimData(json).toString("hex").toUpperCase();
return signingClaimData(json as ClaimObject)
.toString("hex")
.toUpperCase();
}
/**
@@ -64,10 +70,12 @@ function encodeForSigningClaim(json: ClaimObject): string {
* @param signer string representing the account to sign the transaction with
* @returns a hex string of the encoded transaction
*/
function encodeForMultisigning(json: JsonObject, signer: string): string {
function encodeForMultisigning(json: object, signer: string): string {
assert(typeof json === "object");
assert.equal(json.SigningPubKey, "");
return multiSigningData(json, signer).toString("hex").toUpperCase();
assert.equal(json["SigningPubKey"], "");
return multiSigningData(json as JsonObject, signer)
.toString("hex")
.toUpperCase();
}
/**

View File

@@ -159,7 +159,7 @@ function ledgerHash(header: ledgerObject): Hash256 {
* @param binary A serialized ledger header
* @returns A JSON object describing a ledger header
*/
function decodeLedgerData(binary: string): ledgerObject {
function decodeLedgerData(binary: string): object {
assert(typeof binary === "string", "binary must be a hex string");
const parser = new BinaryParser(binary);
return {