Allow more loose input format for RLP encoder (#4402).

This commit is contained in:
Richard Moore 2023-10-09 18:35:44 -04:00
parent 06db040822
commit 9a4b753445
4 changed files with 10 additions and 5 deletions

@ -186,7 +186,7 @@ export type {
ErrorCode,
FixedFormat,
Utf8ErrorFunc, UnicodeNormalizationForm, Utf8ErrorReason,
RlpStructuredData,
RlpStructuredData, RlpStructuredDataish,
GetUrlResponse,
FetchPreflightFunc, FetchProcessFunc, FetchRetryFunc,

@ -86,7 +86,7 @@ export type { FixedFormat } from "./fixednumber.js"
export type { BigNumberish, Numeric } from "./maths.js";
export type { RlpStructuredData } from "./rlp.js";
export type { RlpStructuredData, RlpStructuredDataish } from "./rlp.js";
export type {
Utf8ErrorFunc,

@ -2,7 +2,7 @@
import { getBytes } from "./data.js";
import type { RlpStructuredData } from "./rlp.js";
import type { RlpStructuredDataish } from "./rlp.js";
function arrayifyInteger(value: number): Array<number> {
@ -14,7 +14,7 @@ function arrayifyInteger(value: number): Array<number> {
return result;
}
function _encode(object: Array<any> | string): Array<number> {
function _encode(object: Array<any> | string | Uint8Array): Array<number> {
if (Array.isArray(object)) {
let payload: Array<number> = [];
object.forEach(function(child) {
@ -54,7 +54,7 @@ const nibbles = "0123456789abcdef";
/**
* Encodes %%object%% as an RLP-encoded [[DataHexString]].
*/
export function encodeRlp(object: RlpStructuredData): string {
export function encodeRlp(object: RlpStructuredDataish): string {
let result = "0x";
for (const v of _encode(object)) {
result += nibbles[v >> 4];

@ -13,3 +13,8 @@ export { encodeRlp } from "./rlp-encode.js";
*/
export type RlpStructuredData = string | Array<RlpStructuredData>;
/**
* An RLP-encoded structure, which allows Uint8Array.
*/
export type RlpStructuredDataish = string | Uint8Array | Array<RlpStructuredDataish>;