Skip to content

Commit

Permalink
Allow more loose input format for RLP encoder (ethers-io#4402).
Browse files Browse the repository at this point in the history
  • Loading branch information
ricmoo authored and Woodpile37 committed Jan 14, 2024
1 parent c52b88c commit 14a3d8c
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src.ts/ethers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ export type {
ErrorCode,
FixedFormat,
Utf8ErrorFunc, UnicodeNormalizationForm, Utf8ErrorReason,
RlpStructuredData,
RlpStructuredData, RlpStructuredDataish,

GetUrlResponse,
FetchPreflightFunc, FetchProcessFunc, FetchRetryFunc,
Expand Down
2 changes: 1 addition & 1 deletion src.ts/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions src.ts/utils/rlp-encode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand All @@ -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) {
Expand Down Expand Up @@ -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];
Expand Down
5 changes: 5 additions & 0 deletions src.ts/utils/rlp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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>;

0 comments on commit 14a3d8c

Please sign in to comment.