@morpho-org/midnight-sdk 2.4.0 → 2.5.0
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/lib/cjs/api/version.generated.d.ts +1 -1
- package/lib/cjs/api/version.generated.js +1 -1
- package/lib/cjs/errors.d.ts +14 -0
- package/lib/cjs/errors.js +19 -1
- package/lib/cjs/signatures/EcrecoverRatifier.d.ts +8 -1
- package/lib/cjs/signatures/EcrecoverRatifier.js +35 -14
- package/lib/esm/api/version.generated.d.ts +1 -1
- package/lib/esm/api/version.generated.js +1 -1
- package/lib/esm/errors.d.ts +14 -0
- package/lib/esm/errors.js +17 -0
- package/lib/esm/signatures/EcrecoverRatifier.d.ts +8 -1
- package/lib/esm/signatures/EcrecoverRatifier.js +36 -15
- package/package.json +3 -3
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/** @internal Installed Midnight SDK package version. */
|
|
2
|
-
export declare const MIDNIGHT_SDK_VERSION = "2.
|
|
2
|
+
export declare const MIDNIGHT_SDK_VERSION = "2.5.0";
|
package/lib/cjs/errors.d.ts
CHANGED
|
@@ -384,6 +384,20 @@ export declare class InvalidTypedDataSignatureError extends Error {
|
|
|
384
384
|
readonly signer: Address;
|
|
385
385
|
constructor(signer: Address, cause?: unknown);
|
|
386
386
|
}
|
|
387
|
+
/**
|
|
388
|
+
* Thrown when an Ecrecover signature cannot be parsed or recovered.
|
|
389
|
+
*
|
|
390
|
+
* @example
|
|
391
|
+
* ```ts
|
|
392
|
+
* import { InvalidEcrecoverSignatureError } from "@morpho-org/midnight-sdk";
|
|
393
|
+
*
|
|
394
|
+
* const error = new InvalidEcrecoverSignatureError(new TypeError("Invalid recovery input"));
|
|
395
|
+
* console.log(error.cause);
|
|
396
|
+
* ```
|
|
397
|
+
*/
|
|
398
|
+
export declare class InvalidEcrecoverSignatureError extends Error {
|
|
399
|
+
constructor(cause: unknown);
|
|
400
|
+
}
|
|
387
401
|
/**
|
|
388
402
|
* Thrown when decoded Ecrecover ratifier data contains a non-canonical signature `v` value.
|
|
389
403
|
*
|
package/lib/cjs/errors.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.InvalidMidnightApiQuoteTargetError = exports.InvalidMidnightApiResponseError = exports.MidnightApiError = exports.InvalidEcrecoverSignatureVError = exports.InvalidTypedDataSignatureError = exports.MidnightMempoolValidationError = exports.ChainIdMismatchError = exports.RatifierV1TakerNotAllowedError = exports.InvalidRatifierV1AddressError = exports.InvalidRateRatifierV1TimeError = exports.InvalidRateRatifierV1TickError = exports.RateRatifierV1BoundOverflowError = exports.InvalidRateRatifierV1RateError = exports.InvalidTreeError = exports.InvalidTreeHeightError = exports.PayloadDecodeError = exports.InvalidOfferParameterError = exports.UnknownCollateralIndexError = exports.InvalidMarketParameterError = exports.InvalidPositionAccrualStateError = exports.InvalidPositionLossFactorError = exports.InvalidPositionAccrualTimestampError = exports.SettlementFeeExceedsPriceError = exports.InvalidTickSpacingError = exports.PriceGreaterThanOneError = exports.TickOutOfRangeError = exports.InvalidOfferGroupError = void 0;
|
|
3
|
+
exports.InvalidMidnightApiQuoteTargetError = exports.InvalidMidnightApiResponseError = exports.MidnightApiError = exports.InvalidEcrecoverSignatureVError = exports.InvalidEcrecoverSignatureError = exports.InvalidTypedDataSignatureError = exports.MidnightMempoolValidationError = exports.ChainIdMismatchError = exports.RatifierV1TakerNotAllowedError = exports.InvalidRatifierV1AddressError = exports.InvalidRateRatifierV1TimeError = exports.InvalidRateRatifierV1TickError = exports.RateRatifierV1BoundOverflowError = exports.InvalidRateRatifierV1RateError = exports.InvalidTreeError = exports.InvalidTreeHeightError = exports.PayloadDecodeError = exports.InvalidOfferParameterError = exports.UnknownCollateralIndexError = exports.InvalidMarketParameterError = exports.InvalidPositionAccrualStateError = exports.InvalidPositionLossFactorError = exports.InvalidPositionAccrualTimestampError = exports.SettlementFeeExceedsPriceError = exports.InvalidTickSpacingError = exports.PriceGreaterThanOneError = exports.TickOutOfRangeError = exports.InvalidOfferGroupError = void 0;
|
|
4
4
|
/**
|
|
5
5
|
* Thrown when a Midnight offer group violates protocol-level group mechanics.
|
|
6
6
|
*
|
|
@@ -483,6 +483,24 @@ class InvalidTypedDataSignatureError extends Error {
|
|
|
483
483
|
}
|
|
484
484
|
}
|
|
485
485
|
exports.InvalidTypedDataSignatureError = InvalidTypedDataSignatureError;
|
|
486
|
+
/**
|
|
487
|
+
* Thrown when an Ecrecover signature cannot be parsed or recovered.
|
|
488
|
+
*
|
|
489
|
+
* @example
|
|
490
|
+
* ```ts
|
|
491
|
+
* import { InvalidEcrecoverSignatureError } from "@morpho-org/midnight-sdk";
|
|
492
|
+
*
|
|
493
|
+
* const error = new InvalidEcrecoverSignatureError(new TypeError("Invalid recovery input"));
|
|
494
|
+
* console.log(error.cause);
|
|
495
|
+
* ```
|
|
496
|
+
*/
|
|
497
|
+
class InvalidEcrecoverSignatureError extends Error {
|
|
498
|
+
constructor(cause) {
|
|
499
|
+
super("Ecrecover signature is malformed. Provide a valid ECDSA signature and try again.", { cause });
|
|
500
|
+
this.name = "InvalidEcrecoverSignatureError";
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
exports.InvalidEcrecoverSignatureError = InvalidEcrecoverSignatureError;
|
|
486
504
|
/**
|
|
487
505
|
* Thrown when decoded Ecrecover ratifier data contains a non-canonical signature `v` value.
|
|
488
506
|
*
|
|
@@ -610,6 +610,7 @@ export declare namespace EcrecoverRatifierUtils {
|
|
|
610
610
|
* @returns Decoded ratifier data plus recovered signer.
|
|
611
611
|
* @throws {ChainIdMismatchError} when `params.chainId` does not match `offer.market.chainId`.
|
|
612
612
|
* @throws {InvalidEcrecoverSignatureVError} when the decoded signature `v` is not 27 or 28.
|
|
613
|
+
* @throws {InvalidEcrecoverSignatureError} when signature recovery fails, preserving the original error as `cause`.
|
|
613
614
|
* @throws {InvalidTreeError} when the proof does not include `offer` in `root`.
|
|
614
615
|
* @throws {InvalidTreeHeightError} when the proof height exceeds 20.
|
|
615
616
|
* @example
|
|
@@ -696,6 +697,7 @@ export declare namespace EcrecoverRatifierUtils {
|
|
|
696
697
|
*
|
|
697
698
|
* @param signature - Hex string or tuple signature.
|
|
698
699
|
* @returns Signature tuple.
|
|
700
|
+
* @throws {InvalidEcrecoverSignatureError} when the serialized signature cannot be parsed, preserving the original error as `cause`.
|
|
699
701
|
* @example
|
|
700
702
|
* ```ts
|
|
701
703
|
* import { EcrecoverRatifierUtils } from "@morpho-org/midnight-sdk";
|
|
@@ -723,6 +725,7 @@ export declare namespace EcrecoverRatifierUtils {
|
|
|
723
725
|
* @param params.leafIndex - Leaf index proven by `params.proof`.
|
|
724
726
|
* @param params.proof - Merkle proof siblings for the leaf.
|
|
725
727
|
* @returns ABI-encoded ratifier data.
|
|
728
|
+
* @throws {InvalidEcrecoverSignatureError} when signature parsing fails, preserving the original error as `cause`.
|
|
726
729
|
* @example
|
|
727
730
|
* ```ts
|
|
728
731
|
* import { EcrecoverRatifierUtils } from "@morpho-org/midnight-sdk";
|
|
@@ -781,6 +784,7 @@ export declare namespace EcrecoverRatifierUtils {
|
|
|
781
784
|
* @param params.signature - Ecrecover signature for the tree root.
|
|
782
785
|
* @returns ABI-encoded EcrecoverRatifier data.
|
|
783
786
|
* @throws {InvalidTreeError} when the leaf index is outside the tree or the tree contains multiple ratifiers.
|
|
787
|
+
* @throws {InvalidEcrecoverSignatureError} when the supplied serialized signature cannot be parsed.
|
|
784
788
|
* @example
|
|
785
789
|
* ```ts
|
|
786
790
|
* import { EcrecoverRatifierUtils, Offer, Tree } from "@morpho-org/midnight-sdk";
|
|
@@ -834,7 +838,8 @@ export declare namespace EcrecoverRatifierUtils {
|
|
|
834
838
|
* @returns Items containing each offer and its ratifier data.
|
|
835
839
|
* @throws {InvalidTreeError} when the tree is invalid or contains multiple ratifiers.
|
|
836
840
|
* @throws {InvalidTreeHeightError} when the tree height is unsupported.
|
|
837
|
-
* @throws {InvalidTypedDataSignatureError} when
|
|
841
|
+
* @throws {InvalidTypedDataSignatureError} when verification fails after signing or after parsing a precomputed signature, including a signer mismatch.
|
|
842
|
+
* @throws {InvalidEcrecoverSignatureError} when a precomputed serialized signature cannot be parsed.
|
|
838
843
|
* @example
|
|
839
844
|
* ```ts
|
|
840
845
|
* import { EcrecoverRatifierUtils, Tree } from "@morpho-org/midnight-sdk";
|
|
@@ -947,6 +952,7 @@ export declare namespace EcrecoverRatifier {
|
|
|
947
952
|
* @throws {InvalidTreeError} When the tag, commitments, or root are invalid.
|
|
948
953
|
* @throws {InvalidTreeHeightError} When the descriptor height is unsupported.
|
|
949
954
|
* @throws {InvalidEcrecoverSignatureVError} When a supplied signature has an unsupported recovery value.
|
|
955
|
+
* @throws {InvalidEcrecoverSignatureError} When a supplied serialized signature cannot be parsed.
|
|
950
956
|
* @example
|
|
951
957
|
* ```ts
|
|
952
958
|
* import { EcrecoverRatifier, type EcrecoverRatifierDataRequest } from "@morpho-org/midnight-sdk";
|
|
@@ -968,6 +974,7 @@ export declare namespace EcrecoverRatifier {
|
|
|
968
974
|
* @throws {ChainIdMismatchError} When the signing client's chain differs from the offers.
|
|
969
975
|
* @throws {InvalidTypedDataSignatureError} When the signature does not recover to the supplied account.
|
|
970
976
|
* @throws {InvalidEcrecoverSignatureVError} When a supplied signature has an unsupported recovery value.
|
|
977
|
+
* @throws {InvalidEcrecoverSignatureError} When a precomputed serialized signature cannot be parsed.
|
|
971
978
|
* @example
|
|
972
979
|
* ```ts
|
|
973
980
|
* import { EcrecoverRatifier, type EcrecoverRatifierRatifyRequest } from "@morpho-org/midnight-sdk";
|
|
@@ -388,6 +388,7 @@ var EcrecoverRatifierUtils;
|
|
|
388
388
|
* @returns Decoded ratifier data plus recovered signer.
|
|
389
389
|
* @throws {ChainIdMismatchError} when `params.chainId` does not match `offer.market.chainId`.
|
|
390
390
|
* @throws {InvalidEcrecoverSignatureVError} when the decoded signature `v` is not 27 or 28.
|
|
391
|
+
* @throws {InvalidEcrecoverSignatureError} when signature recovery fails, preserving the original error as `cause`.
|
|
391
392
|
* @throws {InvalidTreeError} when the proof does not include `offer` in `root`.
|
|
392
393
|
* @throws {InvalidTreeHeightError} when the proof height exceeds 20.
|
|
393
394
|
* @example
|
|
@@ -413,19 +414,27 @@ var EcrecoverRatifierUtils;
|
|
|
413
414
|
})) {
|
|
414
415
|
throw new errors_js_1.InvalidTreeError("Ratifier data proof does not include offer.");
|
|
415
416
|
}
|
|
416
|
-
const
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
proofLength: decoded.proof.length,
|
|
422
|
-
}),
|
|
423
|
-
signature: (0, viem_1.serializeSignature)({
|
|
424
|
-
r: decoded.signature.r,
|
|
425
|
-
s: decoded.signature.s,
|
|
426
|
-
yParity: toCanonicalYParity(decoded.signature.v),
|
|
427
|
-
}),
|
|
417
|
+
const hash = digestForRoot({
|
|
418
|
+
chainId: params.chainId,
|
|
419
|
+
offer,
|
|
420
|
+
root: decoded.root,
|
|
421
|
+
proofLength: decoded.proof.length,
|
|
428
422
|
});
|
|
423
|
+
const yParity = toCanonicalYParity(decoded.signature.v);
|
|
424
|
+
let signer;
|
|
425
|
+
try {
|
|
426
|
+
signer = await (0, viem_1.recoverAddress)({
|
|
427
|
+
hash,
|
|
428
|
+
signature: (0, viem_1.serializeSignature)({
|
|
429
|
+
r: decoded.signature.r,
|
|
430
|
+
s: decoded.signature.s,
|
|
431
|
+
yParity,
|
|
432
|
+
}),
|
|
433
|
+
});
|
|
434
|
+
}
|
|
435
|
+
catch (cause) {
|
|
436
|
+
throw new errors_js_1.InvalidEcrecoverSignatureError(cause);
|
|
437
|
+
}
|
|
429
438
|
return (0, morpho_ts_1.deepFreeze)({
|
|
430
439
|
...decoded,
|
|
431
440
|
signer,
|
|
@@ -542,6 +551,7 @@ var EcrecoverRatifierUtils;
|
|
|
542
551
|
*
|
|
543
552
|
* @param signature - Hex string or tuple signature.
|
|
544
553
|
* @returns Signature tuple.
|
|
554
|
+
* @throws {InvalidEcrecoverSignatureError} when the serialized signature cannot be parsed, preserving the original error as `cause`.
|
|
545
555
|
* @example
|
|
546
556
|
* ```ts
|
|
547
557
|
* import { EcrecoverRatifierUtils } from "@morpho-org/midnight-sdk";
|
|
@@ -564,7 +574,13 @@ var EcrecoverRatifierUtils;
|
|
|
564
574
|
s: signature.s,
|
|
565
575
|
};
|
|
566
576
|
}
|
|
567
|
-
|
|
577
|
+
let parsed;
|
|
578
|
+
try {
|
|
579
|
+
parsed = (0, viem_1.parseSignature)(signature);
|
|
580
|
+
}
|
|
581
|
+
catch (cause) {
|
|
582
|
+
throw new errors_js_1.InvalidEcrecoverSignatureError(cause);
|
|
583
|
+
}
|
|
568
584
|
const v = Number(parsed.v ?? BigInt(parsed.yParity));
|
|
569
585
|
return {
|
|
570
586
|
v: v < 27 ? v + 27 : v,
|
|
@@ -584,6 +600,7 @@ var EcrecoverRatifierUtils;
|
|
|
584
600
|
* @param params.leafIndex - Leaf index proven by `params.proof`.
|
|
585
601
|
* @param params.proof - Merkle proof siblings for the leaf.
|
|
586
602
|
* @returns ABI-encoded ratifier data.
|
|
603
|
+
* @throws {InvalidEcrecoverSignatureError} when signature parsing fails, preserving the original error as `cause`.
|
|
587
604
|
* @example
|
|
588
605
|
* ```ts
|
|
589
606
|
* import { EcrecoverRatifierUtils } from "@morpho-org/midnight-sdk";
|
|
@@ -663,6 +680,7 @@ var EcrecoverRatifierUtils;
|
|
|
663
680
|
* @param params.signature - Ecrecover signature for the tree root.
|
|
664
681
|
* @returns ABI-encoded EcrecoverRatifier data.
|
|
665
682
|
* @throws {InvalidTreeError} when the leaf index is outside the tree or the tree contains multiple ratifiers.
|
|
683
|
+
* @throws {InvalidEcrecoverSignatureError} when the supplied serialized signature cannot be parsed.
|
|
666
684
|
* @example
|
|
667
685
|
* ```ts
|
|
668
686
|
* import { EcrecoverRatifierUtils, Offer, Tree } from "@morpho-org/midnight-sdk";
|
|
@@ -729,7 +747,8 @@ var EcrecoverRatifierUtils;
|
|
|
729
747
|
* @returns Items containing each offer and its ratifier data.
|
|
730
748
|
* @throws {InvalidTreeError} when the tree is invalid or contains multiple ratifiers.
|
|
731
749
|
* @throws {InvalidTreeHeightError} when the tree height is unsupported.
|
|
732
|
-
* @throws {InvalidTypedDataSignatureError} when
|
|
750
|
+
* @throws {InvalidTypedDataSignatureError} when verification fails after signing or after parsing a precomputed signature, including a signer mismatch.
|
|
751
|
+
* @throws {InvalidEcrecoverSignatureError} when a precomputed serialized signature cannot be parsed.
|
|
733
752
|
* @example
|
|
734
753
|
* ```ts
|
|
735
754
|
* import { EcrecoverRatifierUtils, Tree } from "@morpho-org/midnight-sdk";
|
|
@@ -911,6 +930,7 @@ var EcrecoverRatifier;
|
|
|
911
930
|
* @throws {InvalidTreeError} When the tag, commitments, or root are invalid.
|
|
912
931
|
* @throws {InvalidTreeHeightError} When the descriptor height is unsupported.
|
|
913
932
|
* @throws {InvalidEcrecoverSignatureVError} When a supplied signature has an unsupported recovery value.
|
|
933
|
+
* @throws {InvalidEcrecoverSignatureError} When a supplied serialized signature cannot be parsed.
|
|
914
934
|
* @example
|
|
915
935
|
* ```ts
|
|
916
936
|
* import { EcrecoverRatifier, type EcrecoverRatifierDataRequest } from "@morpho-org/midnight-sdk";
|
|
@@ -936,6 +956,7 @@ var EcrecoverRatifier;
|
|
|
936
956
|
* @throws {ChainIdMismatchError} When the signing client's chain differs from the offers.
|
|
937
957
|
* @throws {InvalidTypedDataSignatureError} When the signature does not recover to the supplied account.
|
|
938
958
|
* @throws {InvalidEcrecoverSignatureVError} When a supplied signature has an unsupported recovery value.
|
|
959
|
+
* @throws {InvalidEcrecoverSignatureError} When a precomputed serialized signature cannot be parsed.
|
|
939
960
|
* @example
|
|
940
961
|
* ```ts
|
|
941
962
|
* import { EcrecoverRatifier, type EcrecoverRatifierRatifyRequest } from "@morpho-org/midnight-sdk";
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/** @internal Installed Midnight SDK package version. */
|
|
2
|
-
export declare const MIDNIGHT_SDK_VERSION = "2.
|
|
2
|
+
export declare const MIDNIGHT_SDK_VERSION = "2.5.0";
|
package/lib/esm/errors.d.ts
CHANGED
|
@@ -384,6 +384,20 @@ export declare class InvalidTypedDataSignatureError extends Error {
|
|
|
384
384
|
readonly signer: Address;
|
|
385
385
|
constructor(signer: Address, cause?: unknown);
|
|
386
386
|
}
|
|
387
|
+
/**
|
|
388
|
+
* Thrown when an Ecrecover signature cannot be parsed or recovered.
|
|
389
|
+
*
|
|
390
|
+
* @example
|
|
391
|
+
* ```ts
|
|
392
|
+
* import { InvalidEcrecoverSignatureError } from "@morpho-org/midnight-sdk";
|
|
393
|
+
*
|
|
394
|
+
* const error = new InvalidEcrecoverSignatureError(new TypeError("Invalid recovery input"));
|
|
395
|
+
* console.log(error.cause);
|
|
396
|
+
* ```
|
|
397
|
+
*/
|
|
398
|
+
export declare class InvalidEcrecoverSignatureError extends Error {
|
|
399
|
+
constructor(cause: unknown);
|
|
400
|
+
}
|
|
387
401
|
/**
|
|
388
402
|
* Thrown when decoded Ecrecover ratifier data contains a non-canonical signature `v` value.
|
|
389
403
|
*
|
package/lib/esm/errors.js
CHANGED
|
@@ -457,6 +457,23 @@ export class InvalidTypedDataSignatureError extends Error {
|
|
|
457
457
|
this.signer = signer;
|
|
458
458
|
}
|
|
459
459
|
}
|
|
460
|
+
/**
|
|
461
|
+
* Thrown when an Ecrecover signature cannot be parsed or recovered.
|
|
462
|
+
*
|
|
463
|
+
* @example
|
|
464
|
+
* ```ts
|
|
465
|
+
* import { InvalidEcrecoverSignatureError } from "@morpho-org/midnight-sdk";
|
|
466
|
+
*
|
|
467
|
+
* const error = new InvalidEcrecoverSignatureError(new TypeError("Invalid recovery input"));
|
|
468
|
+
* console.log(error.cause);
|
|
469
|
+
* ```
|
|
470
|
+
*/
|
|
471
|
+
export class InvalidEcrecoverSignatureError extends Error {
|
|
472
|
+
constructor(cause) {
|
|
473
|
+
super("Ecrecover signature is malformed. Provide a valid ECDSA signature and try again.", { cause });
|
|
474
|
+
this.name = "InvalidEcrecoverSignatureError";
|
|
475
|
+
}
|
|
476
|
+
}
|
|
460
477
|
/**
|
|
461
478
|
* Thrown when decoded Ecrecover ratifier data contains a non-canonical signature `v` value.
|
|
462
479
|
*
|
|
@@ -610,6 +610,7 @@ export declare namespace EcrecoverRatifierUtils {
|
|
|
610
610
|
* @returns Decoded ratifier data plus recovered signer.
|
|
611
611
|
* @throws {ChainIdMismatchError} when `params.chainId` does not match `offer.market.chainId`.
|
|
612
612
|
* @throws {InvalidEcrecoverSignatureVError} when the decoded signature `v` is not 27 or 28.
|
|
613
|
+
* @throws {InvalidEcrecoverSignatureError} when signature recovery fails, preserving the original error as `cause`.
|
|
613
614
|
* @throws {InvalidTreeError} when the proof does not include `offer` in `root`.
|
|
614
615
|
* @throws {InvalidTreeHeightError} when the proof height exceeds 20.
|
|
615
616
|
* @example
|
|
@@ -696,6 +697,7 @@ export declare namespace EcrecoverRatifierUtils {
|
|
|
696
697
|
*
|
|
697
698
|
* @param signature - Hex string or tuple signature.
|
|
698
699
|
* @returns Signature tuple.
|
|
700
|
+
* @throws {InvalidEcrecoverSignatureError} when the serialized signature cannot be parsed, preserving the original error as `cause`.
|
|
699
701
|
* @example
|
|
700
702
|
* ```ts
|
|
701
703
|
* import { EcrecoverRatifierUtils } from "@morpho-org/midnight-sdk";
|
|
@@ -723,6 +725,7 @@ export declare namespace EcrecoverRatifierUtils {
|
|
|
723
725
|
* @param params.leafIndex - Leaf index proven by `params.proof`.
|
|
724
726
|
* @param params.proof - Merkle proof siblings for the leaf.
|
|
725
727
|
* @returns ABI-encoded ratifier data.
|
|
728
|
+
* @throws {InvalidEcrecoverSignatureError} when signature parsing fails, preserving the original error as `cause`.
|
|
726
729
|
* @example
|
|
727
730
|
* ```ts
|
|
728
731
|
* import { EcrecoverRatifierUtils } from "@morpho-org/midnight-sdk";
|
|
@@ -781,6 +784,7 @@ export declare namespace EcrecoverRatifierUtils {
|
|
|
781
784
|
* @param params.signature - Ecrecover signature for the tree root.
|
|
782
785
|
* @returns ABI-encoded EcrecoverRatifier data.
|
|
783
786
|
* @throws {InvalidTreeError} when the leaf index is outside the tree or the tree contains multiple ratifiers.
|
|
787
|
+
* @throws {InvalidEcrecoverSignatureError} when the supplied serialized signature cannot be parsed.
|
|
784
788
|
* @example
|
|
785
789
|
* ```ts
|
|
786
790
|
* import { EcrecoverRatifierUtils, Offer, Tree } from "@morpho-org/midnight-sdk";
|
|
@@ -834,7 +838,8 @@ export declare namespace EcrecoverRatifierUtils {
|
|
|
834
838
|
* @returns Items containing each offer and its ratifier data.
|
|
835
839
|
* @throws {InvalidTreeError} when the tree is invalid or contains multiple ratifiers.
|
|
836
840
|
* @throws {InvalidTreeHeightError} when the tree height is unsupported.
|
|
837
|
-
* @throws {InvalidTypedDataSignatureError} when
|
|
841
|
+
* @throws {InvalidTypedDataSignatureError} when verification fails after signing or after parsing a precomputed signature, including a signer mismatch.
|
|
842
|
+
* @throws {InvalidEcrecoverSignatureError} when a precomputed serialized signature cannot be parsed.
|
|
838
843
|
* @example
|
|
839
844
|
* ```ts
|
|
840
845
|
* import { EcrecoverRatifierUtils, Tree } from "@morpho-org/midnight-sdk";
|
|
@@ -947,6 +952,7 @@ export declare namespace EcrecoverRatifier {
|
|
|
947
952
|
* @throws {InvalidTreeError} When the tag, commitments, or root are invalid.
|
|
948
953
|
* @throws {InvalidTreeHeightError} When the descriptor height is unsupported.
|
|
949
954
|
* @throws {InvalidEcrecoverSignatureVError} When a supplied signature has an unsupported recovery value.
|
|
955
|
+
* @throws {InvalidEcrecoverSignatureError} When a supplied serialized signature cannot be parsed.
|
|
950
956
|
* @example
|
|
951
957
|
* ```ts
|
|
952
958
|
* import { EcrecoverRatifier, type EcrecoverRatifierDataRequest } from "@morpho-org/midnight-sdk";
|
|
@@ -968,6 +974,7 @@ export declare namespace EcrecoverRatifier {
|
|
|
968
974
|
* @throws {ChainIdMismatchError} When the signing client's chain differs from the offers.
|
|
969
975
|
* @throws {InvalidTypedDataSignatureError} When the signature does not recover to the supplied account.
|
|
970
976
|
* @throws {InvalidEcrecoverSignatureVError} When a supplied signature has an unsupported recovery value.
|
|
977
|
+
* @throws {InvalidEcrecoverSignatureError} When a precomputed serialized signature cannot be parsed.
|
|
971
978
|
* @example
|
|
972
979
|
* ```ts
|
|
973
980
|
* import { EcrecoverRatifier, type EcrecoverRatifierRatifyRequest } from "@morpho-org/midnight-sdk";
|
|
@@ -2,7 +2,7 @@ import { deepFreeze } from "@morpho-org/morpho-ts";
|
|
|
2
2
|
import { decodeAbiParameters, encodeAbiParameters, keccak256, parseSignature, recoverAddress, serializeSignature, verifyHash, } from "viem";
|
|
3
3
|
import { signTypedData } from "viem/actions";
|
|
4
4
|
import { EIP712_DOMAIN_TYPEHASH } from "../constants.js";
|
|
5
|
-
import { ChainIdMismatchError, InvalidEcrecoverSignatureVError, InvalidTreeError, InvalidTreeHeightError, InvalidTypedDataSignatureError, } from "../errors.js";
|
|
5
|
+
import { ChainIdMismatchError, InvalidEcrecoverSignatureError, InvalidEcrecoverSignatureVError, InvalidTreeError, InvalidTreeHeightError, InvalidTypedDataSignatureError, } from "../errors.js";
|
|
6
6
|
import { MarketParams } from "../market/index.js";
|
|
7
7
|
import { Offer } from "../offers/index.js";
|
|
8
8
|
import { eip712Digest } from "./eip712.js";
|
|
@@ -385,6 +385,7 @@ export var EcrecoverRatifierUtils;
|
|
|
385
385
|
* @returns Decoded ratifier data plus recovered signer.
|
|
386
386
|
* @throws {ChainIdMismatchError} when `params.chainId` does not match `offer.market.chainId`.
|
|
387
387
|
* @throws {InvalidEcrecoverSignatureVError} when the decoded signature `v` is not 27 or 28.
|
|
388
|
+
* @throws {InvalidEcrecoverSignatureError} when signature recovery fails, preserving the original error as `cause`.
|
|
388
389
|
* @throws {InvalidTreeError} when the proof does not include `offer` in `root`.
|
|
389
390
|
* @throws {InvalidTreeHeightError} when the proof height exceeds 20.
|
|
390
391
|
* @example
|
|
@@ -410,19 +411,27 @@ export var EcrecoverRatifierUtils;
|
|
|
410
411
|
})) {
|
|
411
412
|
throw new InvalidTreeError("Ratifier data proof does not include offer.");
|
|
412
413
|
}
|
|
413
|
-
const
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
proofLength: decoded.proof.length,
|
|
419
|
-
}),
|
|
420
|
-
signature: serializeSignature({
|
|
421
|
-
r: decoded.signature.r,
|
|
422
|
-
s: decoded.signature.s,
|
|
423
|
-
yParity: toCanonicalYParity(decoded.signature.v),
|
|
424
|
-
}),
|
|
414
|
+
const hash = digestForRoot({
|
|
415
|
+
chainId: params.chainId,
|
|
416
|
+
offer,
|
|
417
|
+
root: decoded.root,
|
|
418
|
+
proofLength: decoded.proof.length,
|
|
425
419
|
});
|
|
420
|
+
const yParity = toCanonicalYParity(decoded.signature.v);
|
|
421
|
+
let signer;
|
|
422
|
+
try {
|
|
423
|
+
signer = await recoverAddress({
|
|
424
|
+
hash,
|
|
425
|
+
signature: serializeSignature({
|
|
426
|
+
r: decoded.signature.r,
|
|
427
|
+
s: decoded.signature.s,
|
|
428
|
+
yParity,
|
|
429
|
+
}),
|
|
430
|
+
});
|
|
431
|
+
}
|
|
432
|
+
catch (cause) {
|
|
433
|
+
throw new InvalidEcrecoverSignatureError(cause);
|
|
434
|
+
}
|
|
426
435
|
return deepFreeze({
|
|
427
436
|
...decoded,
|
|
428
437
|
signer,
|
|
@@ -539,6 +548,7 @@ export var EcrecoverRatifierUtils;
|
|
|
539
548
|
*
|
|
540
549
|
* @param signature - Hex string or tuple signature.
|
|
541
550
|
* @returns Signature tuple.
|
|
551
|
+
* @throws {InvalidEcrecoverSignatureError} when the serialized signature cannot be parsed, preserving the original error as `cause`.
|
|
542
552
|
* @example
|
|
543
553
|
* ```ts
|
|
544
554
|
* import { EcrecoverRatifierUtils } from "@morpho-org/midnight-sdk";
|
|
@@ -561,7 +571,13 @@ export var EcrecoverRatifierUtils;
|
|
|
561
571
|
s: signature.s,
|
|
562
572
|
};
|
|
563
573
|
}
|
|
564
|
-
|
|
574
|
+
let parsed;
|
|
575
|
+
try {
|
|
576
|
+
parsed = parseSignature(signature);
|
|
577
|
+
}
|
|
578
|
+
catch (cause) {
|
|
579
|
+
throw new InvalidEcrecoverSignatureError(cause);
|
|
580
|
+
}
|
|
565
581
|
const v = Number(parsed.v ?? BigInt(parsed.yParity));
|
|
566
582
|
return {
|
|
567
583
|
v: v < 27 ? v + 27 : v,
|
|
@@ -581,6 +597,7 @@ export var EcrecoverRatifierUtils;
|
|
|
581
597
|
* @param params.leafIndex - Leaf index proven by `params.proof`.
|
|
582
598
|
* @param params.proof - Merkle proof siblings for the leaf.
|
|
583
599
|
* @returns ABI-encoded ratifier data.
|
|
600
|
+
* @throws {InvalidEcrecoverSignatureError} when signature parsing fails, preserving the original error as `cause`.
|
|
584
601
|
* @example
|
|
585
602
|
* ```ts
|
|
586
603
|
* import { EcrecoverRatifierUtils } from "@morpho-org/midnight-sdk";
|
|
@@ -660,6 +677,7 @@ export var EcrecoverRatifierUtils;
|
|
|
660
677
|
* @param params.signature - Ecrecover signature for the tree root.
|
|
661
678
|
* @returns ABI-encoded EcrecoverRatifier data.
|
|
662
679
|
* @throws {InvalidTreeError} when the leaf index is outside the tree or the tree contains multiple ratifiers.
|
|
680
|
+
* @throws {InvalidEcrecoverSignatureError} when the supplied serialized signature cannot be parsed.
|
|
663
681
|
* @example
|
|
664
682
|
* ```ts
|
|
665
683
|
* import { EcrecoverRatifierUtils, Offer, Tree } from "@morpho-org/midnight-sdk";
|
|
@@ -726,7 +744,8 @@ export var EcrecoverRatifierUtils;
|
|
|
726
744
|
* @returns Items containing each offer and its ratifier data.
|
|
727
745
|
* @throws {InvalidTreeError} when the tree is invalid or contains multiple ratifiers.
|
|
728
746
|
* @throws {InvalidTreeHeightError} when the tree height is unsupported.
|
|
729
|
-
* @throws {InvalidTypedDataSignatureError} when
|
|
747
|
+
* @throws {InvalidTypedDataSignatureError} when verification fails after signing or after parsing a precomputed signature, including a signer mismatch.
|
|
748
|
+
* @throws {InvalidEcrecoverSignatureError} when a precomputed serialized signature cannot be parsed.
|
|
730
749
|
* @example
|
|
731
750
|
* ```ts
|
|
732
751
|
* import { EcrecoverRatifierUtils, Tree } from "@morpho-org/midnight-sdk";
|
|
@@ -908,6 +927,7 @@ export var EcrecoverRatifier;
|
|
|
908
927
|
* @throws {InvalidTreeError} When the tag, commitments, or root are invalid.
|
|
909
928
|
* @throws {InvalidTreeHeightError} When the descriptor height is unsupported.
|
|
910
929
|
* @throws {InvalidEcrecoverSignatureVError} When a supplied signature has an unsupported recovery value.
|
|
930
|
+
* @throws {InvalidEcrecoverSignatureError} When a supplied serialized signature cannot be parsed.
|
|
911
931
|
* @example
|
|
912
932
|
* ```ts
|
|
913
933
|
* import { EcrecoverRatifier, type EcrecoverRatifierDataRequest } from "@morpho-org/midnight-sdk";
|
|
@@ -933,6 +953,7 @@ export var EcrecoverRatifier;
|
|
|
933
953
|
* @throws {ChainIdMismatchError} When the signing client's chain differs from the offers.
|
|
934
954
|
* @throws {InvalidTypedDataSignatureError} When the signature does not recover to the supplied account.
|
|
935
955
|
* @throws {InvalidEcrecoverSignatureVError} When a supplied signature has an unsupported recovery value.
|
|
956
|
+
* @throws {InvalidEcrecoverSignatureError} When a precomputed serialized signature cannot be parsed.
|
|
936
957
|
* @example
|
|
937
958
|
* ```ts
|
|
938
959
|
* import { EcrecoverRatifier, type EcrecoverRatifierRatifyRequest } from "@morpho-org/midnight-sdk";
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@morpho-org/midnight-sdk",
|
|
3
3
|
"description": "Viem-based package for Morpho Midnight that exports protocol utilities, fetch helpers, and Midnight API utilities under a dedicated API subpath.",
|
|
4
|
-
"version": "2.
|
|
4
|
+
"version": "2.5.0",
|
|
5
5
|
"author": "Morpho Association <contact@morpho.org>",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -45,8 +45,8 @@
|
|
|
45
45
|
"viem": "^2.0.0"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
|
-
"@morpho-org/morpho-ts": "^4.
|
|
49
|
-
"@morpho-org/test": "^2.12.
|
|
48
|
+
"@morpho-org/morpho-ts": "^4.3.0",
|
|
49
|
+
"@morpho-org/test": "^2.12.1",
|
|
50
50
|
"fast-check": "^4.9.0",
|
|
51
51
|
"typescript": "7.0.2",
|
|
52
52
|
"viem": "^2.55.10",
|