Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion src.ts/abi/coders/boolean.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Typed } from "../typed.js";
import { Coder } from "./abstract-coder.js";
import { assert } from "../../utils/index.js";

import type { Reader, Writer } from "./abstract-coder.js";

Expand All @@ -22,6 +23,22 @@ export class BooleanCoder extends Coder {
}

decode(reader: Reader): any {
return !!reader.readValue();
const bytes = reader.readBytes(32, false);

for (let i = 0; i < 31; i++) {
assert(
bytes[i] === 0,
`Boolean padding error: byte[${i}]=0x${bytes[i].toString(16)}`,
"INVALID_ARGUMENT"
);
}

const v = bytes[31];
assert(
v === 0 || v === 1,
`Boolean value error: expected 0 or 1 but got 0x${v.toString(16)}`,
"INVALID_ARGUMENT"
);
return v === 1;
}
}