-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
47 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@across-protocol/integrator-sdk": patch | ||
--- | ||
|
||
stricter integrator id check |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,35 @@ | ||
import { concat, Hex, toHex } from "viem"; | ||
import { concat, Hex, isHex } from "viem"; | ||
|
||
export const DOMAIN_CALLDATA_DELIMITER = "0x1dc0de"; | ||
|
||
export function tagIntegratorId(integratorId: string, txData: Hex) { | ||
return concat([txData, DOMAIN_CALLDATA_DELIMITER, toHex(integratorId)]); | ||
export function tagIntegratorId(integratorId: Hex, txData: Hex) { | ||
assertValidIntegratorId(integratorId); | ||
|
||
return concat([txData, DOMAIN_CALLDATA_DELIMITER, integratorId]); | ||
} | ||
|
||
export function getIntegratorDataSuffix(integratorId: Hex) { | ||
assertValidIntegratorId(integratorId); | ||
|
||
return concat([DOMAIN_CALLDATA_DELIMITER, integratorId]); | ||
} | ||
|
||
export function getIntegratorDataSuffix(integratorId: string) { | ||
return concat([DOMAIN_CALLDATA_DELIMITER, toHex(integratorId)]); | ||
export function isValidIntegratorId(integratorId: string) { | ||
return ( | ||
isHex(integratorId) && | ||
// "0x" + 2 bytes = 6 hex characters | ||
integratorId.length === 6 | ||
); | ||
} | ||
|
||
export function assertValidIntegratorId( | ||
integratorId: string, | ||
): integratorId is Hex { | ||
if (!isValidIntegratorId(integratorId)) { | ||
throw new Error( | ||
`Invalid integrator ID: ${integratorId}. Needs to be 2 bytes hex string.`, | ||
); | ||
} | ||
|
||
return true; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters