Skip to content

Commit

Permalink
Removes utils library because it breaks ts-node TypeStrong/ts-node#783.
Browse files Browse the repository at this point in the history
Unfortunately, at the moment you have to choose whether to write imports that work in ts-node, or that work in the browser as es-modules.  Luckily, for this project there was one function in a second file so we can just pull that into the index file and circumvent the problem.  For other projects, resolving this issue will get a lot more messy.
  • Loading branch information
MicahZoltu committed Jun 26, 2019
1 parent c152c6a commit 48c9a74
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 113 deletions.
102 changes: 4 additions & 98 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@zoltu/rlp-encoder",
"description": "Dependency free library for doing RLP encoding.",
"version": "1.0.0",
"version": "1.0.1",
"repository": {},
"license": "Unlicense",
"main": "output-node/index.js",
Expand Down
15 changes: 13 additions & 2 deletions source/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { hexStringToUint8Array } from './utils'

export type RlpItem = Uint8Array | RlpItemArray
export interface RlpItemArray extends Array<RlpItem> {}

Expand Down Expand Up @@ -69,3 +67,16 @@ function rlpEncodeLarge(data: Uint8Array): Uint8Array {
result.set(data, 1 + lengthBytes.length)
return result
}

function hexStringToUint8Array(hex: string): Uint8Array {
const match = new RegExp(`^(?:0x)?([a-fA-F0-9]*)$`).exec(hex)
if (match === null) throw new Error(`Expected a hex string encoded byte array with an optional '0x' prefix but received ${hex}`)
const maybeLeadingZero = (match[1].length % 2) ? '0' : ''
const normalized = `${maybeLeadingZero}${match[1]}`
const byteLength = normalized.length / 2
const bytes = new Uint8Array(byteLength)
for (let i = 0; i < byteLength; ++i) {
bytes[i] = (Number.parseInt(`${normalized[i*2]}${normalized[i*2+1]}`, 16))
}
return bytes
}
12 changes: 0 additions & 12 deletions source/utils.ts

This file was deleted.

0 comments on commit 48c9a74

Please sign in to comment.