Skip to content

Commit 9a4b753

Browse files
committedOct 9, 2023
Allow more loose input format for RLP encoder (#4402).
1 parent 06db040 commit 9a4b753

File tree

4 files changed

+10
-5
lines changed

4 files changed

+10
-5
lines changed
 

‎src.ts/ethers.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ export type {
186186
ErrorCode,
187187
FixedFormat,
188188
Utf8ErrorFunc, UnicodeNormalizationForm, Utf8ErrorReason,
189-
RlpStructuredData,
189+
RlpStructuredData, RlpStructuredDataish,
190190

191191
GetUrlResponse,
192192
FetchPreflightFunc, FetchProcessFunc, FetchRetryFunc,

‎src.ts/utils/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ export type { FixedFormat } from "./fixednumber.js"
8686

8787
export type { BigNumberish, Numeric } from "./maths.js";
8888

89-
export type { RlpStructuredData } from "./rlp.js";
89+
export type { RlpStructuredData, RlpStructuredDataish } from "./rlp.js";
9090

9191
export type {
9292
Utf8ErrorFunc,

‎src.ts/utils/rlp-encode.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import { getBytes } from "./data.js";
44

5-
import type { RlpStructuredData } from "./rlp.js";
5+
import type { RlpStructuredDataish } from "./rlp.js";
66

77

88
function arrayifyInteger(value: number): Array<number> {
@@ -14,7 +14,7 @@ function arrayifyInteger(value: number): Array<number> {
1414
return result;
1515
}
1616

17-
function _encode(object: Array<any> | string): Array<number> {
17+
function _encode(object: Array<any> | string | Uint8Array): Array<number> {
1818
if (Array.isArray(object)) {
1919
let payload: Array<number> = [];
2020
object.forEach(function(child) {
@@ -54,7 +54,7 @@ const nibbles = "0123456789abcdef";
5454
/**
5555
* Encodes %%object%% as an RLP-encoded [[DataHexString]].
5656
*/
57-
export function encodeRlp(object: RlpStructuredData): string {
57+
export function encodeRlp(object: RlpStructuredDataish): string {
5858
let result = "0x";
5959
for (const v of _encode(object)) {
6060
result += nibbles[v >> 4];

‎src.ts/utils/rlp.ts

+5
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,8 @@ export { encodeRlp } from "./rlp-encode.js";
1313
*/
1414
export type RlpStructuredData = string | Array<RlpStructuredData>;
1515

16+
/**
17+
* An RLP-encoded structure, which allows Uint8Array.
18+
*/
19+
export type RlpStructuredDataish = string | Uint8Array | Array<RlpStructuredDataish>;
20+

0 commit comments

Comments
 (0)
Please sign in to comment.