Skip to content

Commit f94a74e

Browse files
committed
Add extra time and hex validations
1 parent 0efdf96 commit f94a74e

File tree

3 files changed

+46
-5
lines changed

3 files changed

+46
-5
lines changed

.changeset/light-bags-raise.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@soundxyz/sdk': patch
3+
---
4+
5+
Add extra time and hex validations

packages/sdk/src/contract/edition-v2/read/create.ts

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
toHex,
1111
} from 'viem'
1212
import { MINT_GAS_LIMIT_MULTIPLIER, UINT32_MAX } from '../../../utils/constants'
13-
import { InvalidUint32 } from '../../../utils/errors'
13+
import { InvalidUint32, InvalidTimeValuesError, InvalidBytes32 } from '../../../utils/errors'
1414
import { curry, exhaustiveGuard, scaleAmount } from '../../../utils/helpers'
1515
import type { Prettify, TransactionGasOptions } from '../../../utils/types'
1616
import type { ContractCall } from '../../types'
@@ -48,6 +48,11 @@ function isValidUint32(value: number) {
4848
return true
4949
}
5050

51+
function isValidBytes32(value: Hex) {
52+
// 2 character for '0x' and then 64 characters for 32 bytes (each byte is 2 hex)
53+
return value.length === 66
54+
}
55+
5156
export function createTieredEditionArgs({
5257
owner,
5358
formattedSalt,
@@ -85,6 +90,13 @@ export function createTieredEditionArgs({
8590
})
8691
}
8792

93+
if (mintConfig.endTime <= mintConfig.startTime) {
94+
throw new InvalidTimeValuesError({
95+
startTime: mintConfig.startTime,
96+
endTime: mintConfig.endTime,
97+
})
98+
}
99+
88100
if (!isValidUint32(mintConfig.maxMintablePerAccount)) {
89101
throw new InvalidUint32({
90102
field: 'mintConfig.maxMintablePerAccount',
@@ -99,6 +111,20 @@ export function createTieredEditionArgs({
99111
})
100112
}
101113

114+
if (!isValidBytes32(mintConfig.affiliateMerkleRoot)) {
115+
throw new InvalidBytes32({
116+
field: 'mintConfig.affiliateMerkleRoot',
117+
value: mintConfig.affiliateMerkleRoot,
118+
})
119+
}
120+
121+
if (mintConfig.mode === 'VERIFY_MERKLE' && !isValidBytes32(mintConfig.merkleRoot)) {
122+
throw new InvalidBytes32({
123+
field: 'mintConfig.merkleRoot',
124+
value: mintConfig.merkleRoot,
125+
})
126+
}
127+
102128
const mode: number = (() => {
103129
switch (mintConfig.mode) {
104130
case 'DEFAULT': {

packages/sdk/src/utils/errors.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -252,14 +252,12 @@ export class InvalidTimeValuesError extends Error {
252252
readonly name = 'InvalidTimeValuesError'
253253

254254
readonly startTime: number
255-
readonly cutoffTime: number
256255
readonly endTime: number
257256

258-
constructor({ startTime, cutoffTime, endTime }: { startTime: number; cutoffTime: number; endTime: number }) {
259-
super('startTime must be earlier than cutoffTime and cutoffTime must be earlier than endTime')
257+
constructor({ startTime, endTime }: { startTime: number; endTime: number }) {
258+
super('startTime must be earlier than endTime')
260259

261260
this.startTime = startTime
262-
this.cutoffTime = cutoffTime
263261
this.endTime = endTime
264262
}
265263
}
@@ -299,3 +297,15 @@ export class InvalidUint32 extends Error {
299297
this.value = value
300298
}
301299
}
300+
301+
export class InvalidBytes32 extends Error {
302+
readonly field: string
303+
readonly value: unknown
304+
305+
constructor({ field, value }: { field: string; value: unknown }) {
306+
super(`Invalid bytes32 for ${field}, this should be 0x followed by 64 characters, but provided ${String(value)}`)
307+
308+
this.field = field
309+
this.value = value
310+
}
311+
}

0 commit comments

Comments
 (0)