(bigint, padLength=0)
| 12 | } |
| 13 | |
| 14 | export function bigIntToU8Array(bigint, padLength=0) { |
| 15 | let hex = bigint.toString(16); |
| 16 | if (padLength === 0) { |
| 17 | padLength = Math.ceil(hex.length / 2); |
| 18 | } |
| 19 | hex = hex.padStart(padLength * 2, '0'); |
| 20 | const length = hex.length / 2; |
| 21 | const arr = new Uint8Array(length); |
| 22 | for (let i = 0; i < length; i++) { |
| 23 | arr[i] = parseInt(hex.slice(i * 2, i * 2 + 2), 16); |
| 24 | } |
| 25 | return arr; |
| 26 | } |
| 27 | |
| 28 | export function u8ArrayToBigInt(arr) { |
| 29 | let hex = '0x'; |
no test coverage detected