Skip to content

Commit 69221ff

Browse files
committed
royalties: added validation of strings to decode
1 parent 25ee1d0 commit 69221ff

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

src/Royalties/decoding.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ import {IV2Royalty, RoyaltyType, UniqueRoyaltyPart} from './types'
44
import {splitStringEvery} from './utils'
55

66
export const decodeRoyaltyPart = (encoded: string): UniqueRoyaltyPart => {
7+
if (encoded.length !== 66) {
8+
throw new Error('Invalid royalty part encoding - length is not 32 bytes ("0x" + 64 symbols)')
9+
}
710
const encodedMeta = encoded.slice(2, 66)
811
const encodedAddress = encoded.slice(2 + 64)
912

@@ -28,6 +31,10 @@ export const decodeRoyaltyPart = (encoded: string): UniqueRoyaltyPart => {
2831
}
2932

3033
export const decodeRoyalties = (encoded: string): UniqueRoyaltyPart[] => {
34+
if (((encoded.length - 2) % 128) !== 0) {
35+
throw new Error('Invalid royalties encoding - length is not multiple of 64 bytes (128 symbols)')
36+
}
37+
3138
const parts = splitStringEvery(encoded.substring(2), 128).map(
3239
(encoded) => '0x' + encoded,
3340
)

0 commit comments

Comments
 (0)