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

@@ -87,6 +87,7 @@ module.exports = {
'@typescript-eslint/no-unsafe-call': 'off',
'@typescript-eslint/no-unsafe-member-access': 'off',
'@typescript-eslint/no-unsafe-assignment': 'off',
'@typescript-eslint/ban-types': 'off',
"spaced-comment": ["error", "always"],
},
},

View File

@@ -10,7 +10,7 @@ Functions to encode/decode to/from the ripple [binary serialization format](http
```
### decode(binary: string): JsonObject
### decode(binary: string): object
Decode a hex-string into a transaction object.
```js
> api.decode('1100612200000000240000000125000000072D0000000055DF530FB14C5304852F20080B0A8EEF3A6BDD044F41F4EBBD68B8B321145FE4FF6240000002540BE4008114D0F5430B66E06498D4CEEC816C7B3337F9982337')
@@ -26,7 +26,7 @@ Decode a hex-string into a transaction object.
}
```
### encode(json: JsonObject): string
### encode(json: object): string
Encode a transaction object into a hex-string.
```js
> api.encode({
@@ -42,15 +42,15 @@ Encode a transaction object into a hex-string.
'1100612200000000240000000125000000072D0000000055DF530FB14C5304852F20080B0A8EEF3A6BDD044F41F4EBBD68B8B321145FE4FF6240000002540BE4008114D0F5430B66E06498D4CEEC816C7B3337F9982337'
```
### encodeForSigning(json: JsonObject): string
### encodeForSigning(json: object): string
Encode the transaction object for signing.
### encodeForSigningClaim(json: ClaimObject): string
### encodeForSigningClaim(json: object): string
Encode the transaction object for payment channel claim.
### encodeForMultisigning(json: JsonObject, signer: string): string
### encodeForMultisigning(json: object, signer: string): string
Encode the transaction object for multi-signing.
@@ -66,7 +66,7 @@ Encode the transaction object for multi-signing.
'195796912.5171664'
```
### decodeLedgerData(binary: string): ledgerObject
### decodeLedgerData(binary: string): object
```js
> api.decodeLedgerData("01E91435016340767BF1C4A3EACEB081770D8ADE216C85445DD6FB002C6B5A2930F2DECE006DA18150CB18F6DD33F6F0990754C962A7CCE62F332FF9C13939B03B864117F0BDA86B6E9B4F873B5C3E520634D343EF5D9D9A4246643D64DAD278BA95DC0EAC6EB5350CF970D521276CDE21276CE60A00")
{

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 {