Skip to content

Commit

Permalink
Fix bytesToArray elementSize initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
Ben-Rey committed May 3, 2024
1 parent 37f31b4 commit 6f1adc0
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -197,15 +197,14 @@ export function bytesToArray<T>(source: Uint8Array, type: ArrayTypes): T[] {
const result: T[] = []
let elementSize: number

if (type !== ArrayTypes.STRING) {
if (type === ArrayTypes.STRING) {
elementSize = bytesToU32(source, byteOffset)
byteOffset += BYTES_32_OFFSET
} else {
elementSize = getDatatypeSize(type)
}

while (byteOffset < sourceLength) {
if (type === ArrayTypes.STRING) {
elementSize = bytesToU32(source, byteOffset)
byteOffset += BYTES_32_OFFSET
}
const elt = source.slice(byteOffset, byteOffset + elementSize)
byteOffset += elementSize

Expand Down
5 changes: 4 additions & 1 deletion packages/massa-web3/src/experimental/crypto/cross-browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,10 @@ async function pbkdf2Browser(
['encrypt', 'decrypt']
)

return Buffer.from(crypto.subtle.exportKey('raw', derivedKey))
const exportedKey = await crypto.subtle.exportKey('raw', derivedKey)

Check warning on line 80 in packages/massa-web3/src/experimental/crypto/cross-browser.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
const buffer = Buffer.from(exportedKey)

Check warning on line 81 in packages/massa-web3/src/experimental/crypto/cross-browser.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement

return buffer

Check warning on line 83 in packages/massa-web3/src/experimental/crypto/cross-browser.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
}

export type PBKDF2Options = {
Expand Down
3 changes: 2 additions & 1 deletion packages/massa-web3/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
"outDir": "./dist"
},
"include": [
"./src/**/*.ts"
"./src/experimental/**/*.ts"
],
"exclude": [
"node_modules",
"**/*.spec.ts"

]
}
9 changes: 4 additions & 5 deletions packages/web3-utils/src/serializers/arrays.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,15 +184,14 @@ export function bytesToArray<T>(source: Uint8Array, type: ArrayTypes): T[] {
const result: T[] = []
let eltSize: number

if (type !== ArrayTypes.STRING) {
if (type === ArrayTypes.STRING) {
eltSize = bytesToU32(source, byteOffset)
byteOffset += 4
} else {
eltSize = getDatatypeSize(type)
}

while (byteOffset < sourceLength) {
if (type === ArrayTypes.STRING) {
eltSize = bytesToU32(source, byteOffset)
byteOffset += 4
}
const elt = source.slice(byteOffset, byteOffset + eltSize)
byteOffset += eltSize

Expand Down

0 comments on commit 6f1adc0

Please sign in to comment.