@omegax/protocol-sdk 0.4.1 → 0.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/protocol.js +1 -1
- package/dist/utils.js +7 -1
- package/package.json +1 -1
package/dist/protocol.js
CHANGED
|
@@ -1172,7 +1172,7 @@ function encodeSubmitOutcomeAttestationData(params) {
|
|
|
1172
1172
|
const outcomeHash = hashStringTo32(params.outcomeId);
|
|
1173
1173
|
const replayHash = hashStringTo32(params.replayKey);
|
|
1174
1174
|
const digest = params.attestationDigestHex
|
|
1175
|
-
? Buffer.from(params.attestationDigestHex
|
|
1175
|
+
? Buffer.from(fromHex(params.attestationDigestHex, 32))
|
|
1176
1176
|
: Buffer.from(hashStringTo32(`${params.cycleId}:${params.outcomeId}:${params.replayKey}`));
|
|
1177
1177
|
if (digest.length !== 32) {
|
|
1178
1178
|
throw new Error('attestation digest must be 32 bytes');
|
package/dist/utils.js
CHANGED
|
@@ -86,7 +86,13 @@ export function toHex(bytes) {
|
|
|
86
86
|
return Buffer.from(bytes).toString('hex');
|
|
87
87
|
}
|
|
88
88
|
export function fromHex(value, expectedLength) {
|
|
89
|
-
const normalized = value.trim().
|
|
89
|
+
const normalized = value.trim().replace(/^0x/i, '');
|
|
90
|
+
if (normalized.length % 2 !== 0) {
|
|
91
|
+
throw new Error('invalid hex string: expected an even number of characters');
|
|
92
|
+
}
|
|
93
|
+
if (!/^[0-9a-fA-F]*$/.test(normalized)) {
|
|
94
|
+
throw new Error('invalid hex string: contains non-hex characters');
|
|
95
|
+
}
|
|
90
96
|
const bytes = Buffer.from(normalized, 'hex');
|
|
91
97
|
if (typeof expectedLength === 'number' && bytes.length !== expectedLength) {
|
|
92
98
|
throw new Error(`invalid hex length: expected ${expectedLength}, got ${bytes.length}`);
|