(value: BytesLike, name?: string, copy?: boolean)
| 26 | export type BytesLike = DataHexString | Uint8Array; |
| 27 | |
| 28 | function _getBytes(value: BytesLike, name?: string, copy?: boolean): Uint8Array { |
| 29 | if (value instanceof Uint8Array) { |
| 30 | if (copy) { return new Uint8Array(value); } |
| 31 | return value; |
| 32 | } |
| 33 | |
| 34 | if (typeof(value) === "string" && value.match(/^0x(?:[0-9a-f][0-9a-f])*$/i)) { |
| 35 | const result = new Uint8Array((value.length - 2) / 2); |
| 36 | let offset = 2; |
| 37 | for (let i = 0; i < result.length; i++) { |
| 38 | result[i] = parseInt(value.substring(offset, offset + 2), 16); |
| 39 | offset += 2; |
| 40 | } |
| 41 | return result; |
| 42 | } |
| 43 | |
| 44 | assertArgument(false, "invalid BytesLike value", name || "value", value); |
| 45 | } |
| 46 | |
| 47 | /** |
| 48 | * Get a typed Uint8Array for %%value%%. If already a Uint8Array |
no test coverage detected