@morpho-org/midnight-sdk 1.7.0 → 2.0.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/MIGRATION-v1-to-v2.md +6 -0
- package/README.md +63 -61
- package/lib/cjs/abis.d.ts +1962 -759
- package/lib/cjs/abis.js +2021 -995
- package/lib/cjs/api/helpers.d.ts +1 -17
- package/lib/cjs/api/helpers.js +0 -4
- package/lib/cjs/api/types.d.ts +5 -4
- package/lib/cjs/api/version.generated.d.ts +1 -1
- package/lib/cjs/api/version.generated.js +2 -2
- package/lib/cjs/bundlesV2.d.ts +15 -0
- package/lib/cjs/bundlesV2.js +2 -0
- package/lib/cjs/constants.d.ts +34 -0
- package/lib/cjs/constants.js +35 -1
- package/lib/cjs/errors.d.ts +107 -0
- package/lib/cjs/errors.js +139 -1
- package/lib/cjs/fetch/Ratifier.d.ts +4 -3
- package/lib/cjs/fetch/Ratifier.js +6 -4
- package/lib/cjs/index.d.ts +8 -0
- package/lib/cjs/index.js +16 -1
- package/lib/cjs/offers/Offer.d.ts +10 -0
- package/lib/cjs/offers/Offer.js +15 -1
- package/lib/cjs/offers/OfferUtils.d.ts +3 -0
- package/lib/cjs/offers/OfferUtils.js +3 -0
- package/lib/cjs/signatures/{EcrecoverRatifierUtils.d.ts → EcrecoverRatifier.d.ts} +118 -2
- package/lib/cjs/signatures/{EcrecoverRatifierUtils.js → EcrecoverRatifier.js} +146 -9
- package/lib/cjs/signatures/GroupUtils.d.ts +55 -2
- package/lib/cjs/signatures/GroupUtils.js +64 -5
- package/lib/cjs/signatures/Payload.d.ts +3 -3
- package/lib/cjs/signatures/PriceRatifierV1.d.ts +472 -0
- package/lib/cjs/signatures/PriceRatifierV1.js +521 -0
- package/lib/cjs/signatures/RateRatifierV1.d.ts +581 -0
- package/lib/cjs/signatures/RateRatifierV1.js +696 -0
- package/lib/{esm/signatures/RatifierUtils.d.ts → cjs/signatures/Ratifier.d.ts} +14 -12
- package/lib/cjs/signatures/{RatifierUtils.js → Ratifier.js} +29 -29
- package/lib/cjs/signatures/{SetterRatifierUtils.d.ts → SetterRatifier.d.ts} +50 -3
- package/lib/cjs/signatures/{SetterRatifierUtils.js → SetterRatifier.js} +65 -7
- package/lib/cjs/signatures/Tree.d.ts +94 -17
- package/lib/cjs/signatures/Tree.js +146 -111
- package/lib/cjs/signatures/TreeUtils.d.ts +191 -21
- package/lib/cjs/signatures/TreeUtils.js +320 -134
- package/lib/cjs/signatures/index.d.ts +7 -3
- package/lib/cjs/signatures/index.js +5 -3
- package/lib/cjs/signatures/ratifierRequests.d.ts +55 -0
- package/lib/cjs/signatures/ratifierRequests.js +2 -0
- package/lib/cjs/signatures/ratifierV1Internal.d.ts +57 -0
- package/lib/cjs/signatures/ratifierV1Internal.js +183 -0
- package/lib/cjs/signatures/standardRatifierInternal.d.ts +4 -0
- package/lib/cjs/signatures/standardRatifierInternal.js +12 -0
- package/lib/cjs/signatures/treeMathInternal.d.ts +4 -0
- package/lib/cjs/signatures/treeMathInternal.js +12 -0
- package/lib/cjs/signatures/treeTypes.d.ts +109 -0
- package/lib/cjs/signatures/treeTypes.js +2 -0
- package/lib/esm/abis.d.ts +1962 -759
- package/lib/esm/abis.js +2020 -994
- package/lib/esm/api/helpers.d.ts +1 -17
- package/lib/esm/api/helpers.js +4 -4
- package/lib/esm/api/types.d.ts +5 -4
- package/lib/esm/api/version.generated.d.ts +1 -1
- package/lib/esm/api/version.generated.js +2 -2
- package/lib/esm/bundlesV2.d.ts +15 -0
- package/lib/esm/bundlesV2.js +1 -0
- package/lib/esm/constants.d.ts +34 -0
- package/lib/esm/constants.js +34 -0
- package/lib/esm/errors.d.ts +107 -0
- package/lib/esm/errors.js +132 -0
- package/lib/esm/fetch/Ratifier.d.ts +4 -3
- package/lib/esm/fetch/Ratifier.js +6 -4
- package/lib/esm/index.d.ts +8 -0
- package/lib/esm/index.js +5 -0
- package/lib/esm/offers/Offer.d.ts +10 -0
- package/lib/esm/offers/Offer.js +15 -1
- package/lib/esm/offers/OfferUtils.d.ts +3 -0
- package/lib/esm/offers/OfferUtils.js +3 -0
- package/lib/esm/signatures/{EcrecoverRatifierUtils.d.ts → EcrecoverRatifier.d.ts} +118 -2
- package/lib/esm/signatures/{EcrecoverRatifierUtils.js → EcrecoverRatifier.js} +146 -9
- package/lib/esm/signatures/GroupUtils.d.ts +55 -2
- package/lib/esm/signatures/GroupUtils.js +64 -5
- package/lib/esm/signatures/Payload.d.ts +3 -3
- package/lib/esm/signatures/PriceRatifierV1.d.ts +472 -0
- package/lib/esm/signatures/PriceRatifierV1.js +520 -0
- package/lib/esm/signatures/RateRatifierV1.d.ts +581 -0
- package/lib/esm/signatures/RateRatifierV1.js +695 -0
- package/lib/{cjs/signatures/RatifierUtils.d.ts → esm/signatures/Ratifier.d.ts} +14 -12
- package/lib/esm/signatures/{RatifierUtils.js → Ratifier.js} +31 -29
- package/lib/esm/signatures/{SetterRatifierUtils.d.ts → SetterRatifier.d.ts} +50 -3
- package/lib/esm/signatures/{SetterRatifierUtils.js → SetterRatifier.js} +65 -7
- package/lib/esm/signatures/Tree.d.ts +94 -17
- package/lib/esm/signatures/Tree.js +147 -112
- package/lib/esm/signatures/TreeUtils.d.ts +191 -21
- package/lib/esm/signatures/TreeUtils.js +318 -132
- package/lib/esm/signatures/index.d.ts +7 -3
- package/lib/esm/signatures/index.js +5 -3
- package/lib/esm/signatures/ratifierRequests.d.ts +55 -0
- package/lib/esm/signatures/ratifierRequests.js +1 -0
- package/lib/esm/signatures/ratifierV1Internal.d.ts +57 -0
- package/lib/esm/signatures/ratifierV1Internal.js +176 -0
- package/lib/esm/signatures/standardRatifierInternal.d.ts +4 -0
- package/lib/esm/signatures/standardRatifierInternal.js +9 -0
- package/lib/esm/signatures/treeMathInternal.d.ts +4 -0
- package/lib/esm/signatures/treeMathInternal.js +8 -0
- package/lib/esm/signatures/treeTypes.d.ts +109 -0
- package/lib/esm/signatures/treeTypes.js +1 -0
- package/package.json +9 -8
|
@@ -2,7 +2,9 @@ import { type BigIntish } from "@morpho-org/morpho-ts";
|
|
|
2
2
|
import { type Account, type Address, type Chain, type Client, type Hash, type Hex, type Signature, type Transport } from "viem";
|
|
3
3
|
import { type IOffer } from "../offers/index.js";
|
|
4
4
|
import type { Payload } from "./Payload.js";
|
|
5
|
-
import {
|
|
5
|
+
import type { EcrecoverRatifierDataRequest, EcrecoverRatifierRatifyRequest, EcrecoverRatifierSignRequest, EcrecoverRatifierTypedDataRequest } from "./ratifierRequests.js";
|
|
6
|
+
import type { RatifierTreeInput } from "./TreeUtils.js";
|
|
7
|
+
import { type TreeProof } from "./TreeUtils.js";
|
|
6
8
|
declare const typedDataTypes: {
|
|
7
9
|
readonly EIP712Domain: readonly [{
|
|
8
10
|
readonly name: "chainId";
|
|
@@ -245,6 +247,7 @@ export type EcrecoverSignatureInput = Hex | Signature | Signature<number, number
|
|
|
245
247
|
* };
|
|
246
248
|
* console.log(params.chainId);
|
|
247
249
|
* ```
|
|
250
|
+
* @deprecated Use {@link EcrecoverRatifierTypedDataRequest} with {@link EcrecoverRatifier}.
|
|
248
251
|
*/
|
|
249
252
|
export interface EcrecoverRatifierTypedDataParams {
|
|
250
253
|
/** Tree-like input being ratified. Existing `Tree` instances reuse cached hashes and proofs. */
|
|
@@ -295,6 +298,7 @@ export interface EcrecoverRatifierTypedDataParams {
|
|
|
295
298
|
* };
|
|
296
299
|
* console.log(params.tree);
|
|
297
300
|
* ```
|
|
301
|
+
* @deprecated Use {@link EcrecoverRatifierRatifyRequest} with {@link EcrecoverRatifier}.
|
|
298
302
|
*/
|
|
299
303
|
export type EcrecoverRatifierRatifyParams = {
|
|
300
304
|
/** Tree-like input being ratified. */
|
|
@@ -357,6 +361,7 @@ export type EcrecoverRatifierRatifyParams = {
|
|
|
357
361
|
* };
|
|
358
362
|
* console.log(params.leafIndex);
|
|
359
363
|
* ```
|
|
364
|
+
* @deprecated Use {@link EcrecoverRatifierDataRequest} with {@link EcrecoverRatifier}.
|
|
360
365
|
*/
|
|
361
366
|
export interface EcrecoverRatifierDataParams {
|
|
362
367
|
/** Tree-like input that produced the proof. Existing `Tree` instances reuse cached hashes and proofs. */
|
|
@@ -419,6 +424,7 @@ export interface VerifiedEcrecoverRatifierData extends DecodedEcrecoverRatifierD
|
|
|
419
424
|
*
|
|
420
425
|
* console.log(EcrecoverRatifierUtils.treeTypeHash(0));
|
|
421
426
|
* ```
|
|
427
|
+
* @deprecated Use {@link EcrecoverRatifier} with a tagged tree.
|
|
422
428
|
*/
|
|
423
429
|
export declare namespace EcrecoverRatifierUtils {
|
|
424
430
|
/**
|
|
@@ -593,7 +599,7 @@ export declare namespace EcrecoverRatifierUtils {
|
|
|
593
599
|
* Verifies an Ecrecover ratifier-data proof and recovers its signer.
|
|
594
600
|
*
|
|
595
601
|
* This helper intentionally does not check `Midnight.isAuthorized` or
|
|
596
|
-
* `
|
|
602
|
+
* `EcrecoverRatifierUtils.isRootCanceled` state. Consumers must query both at the
|
|
597
603
|
* observed block before treating a recovered item as executable: the returned
|
|
598
604
|
* signer must be the maker or authorized by the maker, the offer ratifier must
|
|
599
605
|
* be authorized by the maker, and `isRootCanceled(maker, root)` must be false.
|
|
@@ -876,4 +882,114 @@ export declare namespace EcrecoverRatifierUtils {
|
|
|
876
882
|
*/
|
|
877
883
|
function ratify(params: EcrecoverRatifierRatifyParams): Promise<readonly Payload.Item[]>;
|
|
878
884
|
}
|
|
885
|
+
/**
|
|
886
|
+
* Tagged-tree API for EcrecoverRatifier with validated portable leaf commitments.
|
|
887
|
+
* Legacy untagged inputs remain available through {@link EcrecoverRatifierUtils}.
|
|
888
|
+
*/
|
|
889
|
+
export declare namespace EcrecoverRatifier {
|
|
890
|
+
/**
|
|
891
|
+
* Builds Ecrecover signing data from a tagged tree.
|
|
892
|
+
* @param request.tree - Matching tagged tree or portable snapshot; commitments are validated before use.
|
|
893
|
+
* @param request.chainId - Chain defining the EIP-712 domain.
|
|
894
|
+
* @returns EIP-712 domain, type definitions, and offer-tree message.
|
|
895
|
+
* @throws {InvalidTreeError} When the tag, commitments, or root are invalid.
|
|
896
|
+
* @throws {InvalidTreeHeightError} When the descriptor height is unsupported.
|
|
897
|
+
* @example
|
|
898
|
+
* ```ts
|
|
899
|
+
* import { EcrecoverRatifier, type EcrecoverRatifierTypedDataRequest } from "@morpho-org/midnight-sdk";
|
|
900
|
+
* function execute(request: EcrecoverRatifierTypedDataRequest) {
|
|
901
|
+
* return EcrecoverRatifier.typedData(request);
|
|
902
|
+
* }
|
|
903
|
+
* ```
|
|
904
|
+
*/
|
|
905
|
+
function typedData(request: EcrecoverRatifierTypedDataRequest): EcrecoverRatificationTypedData;
|
|
906
|
+
/**
|
|
907
|
+
* Computes the signing digest of a tagged Ecrecover tree.
|
|
908
|
+
* @param request.tree - Matching tagged tree or portable snapshot; commitments are validated before use.
|
|
909
|
+
* @param request.chainId - Chain defining the EIP-712 domain.
|
|
910
|
+
* @returns The EIP-712 signing digest.
|
|
911
|
+
* @throws {InvalidTreeError} When the tag, commitments, or root are invalid.
|
|
912
|
+
* @throws {InvalidTreeHeightError} When the descriptor height is unsupported.
|
|
913
|
+
* @example
|
|
914
|
+
* ```ts
|
|
915
|
+
* import { EcrecoverRatifier, type EcrecoverRatifierTypedDataRequest } from "@morpho-org/midnight-sdk";
|
|
916
|
+
* function execute(request: EcrecoverRatifierTypedDataRequest) {
|
|
917
|
+
* return EcrecoverRatifier.digest(request);
|
|
918
|
+
* }
|
|
919
|
+
* ```
|
|
920
|
+
*/
|
|
921
|
+
function digest(request: EcrecoverRatifierTypedDataRequest): Hash;
|
|
922
|
+
/**
|
|
923
|
+
* Signs a tagged Ecrecover tree using the supplied client and account.
|
|
924
|
+
* @param request.tree - Matching tagged tree or portable snapshot; commitments are validated before use.
|
|
925
|
+
* @param request.account - Maker or authorized signer.
|
|
926
|
+
* @param request.client - Signing client; omit when ratify receives a precomputed signature.
|
|
927
|
+
* @returns A verified hex signature over the tree.
|
|
928
|
+
* @throws {InvalidTreeError} When the tag, commitments, or root are invalid.
|
|
929
|
+
* @throws {InvalidTreeHeightError} When the descriptor height is unsupported.
|
|
930
|
+
* @throws {ChainIdMismatchError} When the signing client's chain differs from the offers.
|
|
931
|
+
* @throws {InvalidTypedDataSignatureError} When the signature does not recover to the supplied account.
|
|
932
|
+
* @example
|
|
933
|
+
* ```ts
|
|
934
|
+
* import { EcrecoverRatifier, type EcrecoverRatifierSignRequest } from "@morpho-org/midnight-sdk";
|
|
935
|
+
* function execute(request: EcrecoverRatifierSignRequest) {
|
|
936
|
+
* return EcrecoverRatifier.sign(request);
|
|
937
|
+
* }
|
|
938
|
+
* ```
|
|
939
|
+
*/
|
|
940
|
+
function sign(request: EcrecoverRatifierSignRequest): Promise<Hex>;
|
|
941
|
+
/**
|
|
942
|
+
* Encodes the signature and proof for one tagged Ecrecover leaf.
|
|
943
|
+
* @param request.tree - Matching tagged tree or portable snapshot; commitments are validated before use.
|
|
944
|
+
* @param request.signature - Tree signature; ratify may instead request one through the supplied client.
|
|
945
|
+
* @param request.leafIndex - Leaf to prove.
|
|
946
|
+
* @returns ABI-encoded ratifier data for the requested leaf.
|
|
947
|
+
* @throws {InvalidTreeError} When the tag, commitments, or root are invalid.
|
|
948
|
+
* @throws {InvalidTreeHeightError} When the descriptor height is unsupported.
|
|
949
|
+
* @throws {InvalidEcrecoverSignatureVError} When a supplied signature has an unsupported recovery value.
|
|
950
|
+
* @example
|
|
951
|
+
* ```ts
|
|
952
|
+
* import { EcrecoverRatifier, type EcrecoverRatifierDataRequest } from "@morpho-org/midnight-sdk";
|
|
953
|
+
* function execute(request: EcrecoverRatifierDataRequest) {
|
|
954
|
+
* return EcrecoverRatifier.ratifierData(request);
|
|
955
|
+
* }
|
|
956
|
+
* ```
|
|
957
|
+
*/
|
|
958
|
+
function ratifierData(request: EcrecoverRatifierDataRequest): Hex;
|
|
959
|
+
/**
|
|
960
|
+
* Builds payload items from a tagged tree and a verified signature.
|
|
961
|
+
* @param request.tree - Matching tagged tree or portable snapshot; commitments are validated before use.
|
|
962
|
+
* @param request.account - Maker or authorized signer.
|
|
963
|
+
* @param request.client - Signing client; omit when ratify receives a precomputed signature.
|
|
964
|
+
* @param request.signature - Tree signature; ratify may instead request one through the supplied client.
|
|
965
|
+
* @returns One payload item per non-padding offer, including its ratifier data.
|
|
966
|
+
* @throws {InvalidTreeError} When the tag, commitments, or root are invalid.
|
|
967
|
+
* @throws {InvalidTreeHeightError} When the descriptor height is unsupported.
|
|
968
|
+
* @throws {ChainIdMismatchError} When the signing client's chain differs from the offers.
|
|
969
|
+
* @throws {InvalidTypedDataSignatureError} When the signature does not recover to the supplied account.
|
|
970
|
+
* @throws {InvalidEcrecoverSignatureVError} When a supplied signature has an unsupported recovery value.
|
|
971
|
+
* @example
|
|
972
|
+
* ```ts
|
|
973
|
+
* import { EcrecoverRatifier, type EcrecoverRatifierRatifyRequest } from "@morpho-org/midnight-sdk";
|
|
974
|
+
* function execute(request: EcrecoverRatifierRatifyRequest) {
|
|
975
|
+
* return EcrecoverRatifier.ratify(request);
|
|
976
|
+
* }
|
|
977
|
+
* ```
|
|
978
|
+
*/
|
|
979
|
+
function ratify(request: EcrecoverRatifierRatifyRequest): Promise<readonly Payload.Item[]>;
|
|
980
|
+
/** {@inheritDoc EcrecoverRatifierUtils.treeTypeHash} */
|
|
981
|
+
const treeTypeHash: typeof EcrecoverRatifierUtils.treeTypeHash;
|
|
982
|
+
/** {@inheritDoc EcrecoverRatifierUtils.digestForRoot} */
|
|
983
|
+
const digestForRoot: typeof EcrecoverRatifierUtils.digestForRoot;
|
|
984
|
+
/** {@inheritDoc EcrecoverRatifierUtils.digestRatifierData} */
|
|
985
|
+
const digestRatifierData: typeof EcrecoverRatifierUtils.digestRatifierData;
|
|
986
|
+
/** {@inheritDoc EcrecoverRatifierUtils.verifyRatifierData} */
|
|
987
|
+
const verifyRatifierData: typeof EcrecoverRatifierUtils.verifyRatifierData;
|
|
988
|
+
/** {@inheritDoc EcrecoverRatifierUtils.toSignature} */
|
|
989
|
+
const toSignature: typeof EcrecoverRatifierUtils.toSignature;
|
|
990
|
+
/** {@inheritDoc EcrecoverRatifierUtils.encodeRatifierData} */
|
|
991
|
+
const encodeRatifierData: typeof EcrecoverRatifierUtils.encodeRatifierData;
|
|
992
|
+
/** {@inheritDoc EcrecoverRatifierUtils.decodeRatifierData} */
|
|
993
|
+
const decodeRatifierData: typeof EcrecoverRatifierUtils.decodeRatifierData;
|
|
994
|
+
}
|
|
879
995
|
export {};
|
|
@@ -6,8 +6,9 @@ import { ChainIdMismatchError, InvalidEcrecoverSignatureVError, InvalidTreeError
|
|
|
6
6
|
import { MarketParams } from "../market/index.js";
|
|
7
7
|
import { Offer } from "../offers/index.js";
|
|
8
8
|
import { eip712Digest } from "./eip712.js";
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
9
|
+
import { Ratifier } from "./Ratifier.js";
|
|
10
|
+
import { parseStandardRatifierTree } from "./standardRatifierInternal.js";
|
|
11
|
+
import { TreeUtils } from "./TreeUtils.js";
|
|
11
12
|
const treeTypeHashes = [
|
|
12
13
|
"0x270da1ebafc0f24637af3612fb8c3a1d828fcb56d3637c24e86dd006b12ca7f9",
|
|
13
14
|
"0x828b9cdf8326a1cf234328e4d5229546a98fb72ef73624f5b6b31538e555b96c",
|
|
@@ -127,6 +128,7 @@ function toCanonicalYParity(v) {
|
|
|
127
128
|
*
|
|
128
129
|
* console.log(EcrecoverRatifierUtils.treeTypeHash(0));
|
|
129
130
|
* ```
|
|
131
|
+
* @deprecated Use {@link EcrecoverRatifier} with a tagged tree.
|
|
130
132
|
*/
|
|
131
133
|
export var EcrecoverRatifierUtils;
|
|
132
134
|
(function (EcrecoverRatifierUtils) {
|
|
@@ -203,7 +205,7 @@ export var EcrecoverRatifierUtils;
|
|
|
203
205
|
* ```
|
|
204
206
|
*/
|
|
205
207
|
function typedData(params) {
|
|
206
|
-
const { tree, ratifier: verifyingContract } =
|
|
208
|
+
const { tree, ratifier: verifyingContract } = Ratifier.normalizeRatifierTree({
|
|
207
209
|
tree: params.tree,
|
|
208
210
|
label: "Ecrecover",
|
|
209
211
|
});
|
|
@@ -272,7 +274,7 @@ export var EcrecoverRatifierUtils;
|
|
|
272
274
|
* ```
|
|
273
275
|
*/
|
|
274
276
|
function digest(params) {
|
|
275
|
-
const { tree, ratifier: verifyingContract } =
|
|
277
|
+
const { tree, ratifier: verifyingContract } = Ratifier.normalizeRatifierTree({
|
|
276
278
|
tree: params.tree,
|
|
277
279
|
label: "Ecrecover",
|
|
278
280
|
});
|
|
@@ -372,7 +374,7 @@ export var EcrecoverRatifierUtils;
|
|
|
372
374
|
* Verifies an Ecrecover ratifier-data proof and recovers its signer.
|
|
373
375
|
*
|
|
374
376
|
* This helper intentionally does not check `Midnight.isAuthorized` or
|
|
375
|
-
* `
|
|
377
|
+
* `EcrecoverRatifierUtils.isRootCanceled` state. Consumers must query both at the
|
|
376
378
|
* observed block before treating a recovered item as executable: the returned
|
|
377
379
|
* signer must be the maker or authorized by the maker, the offer ratifier must
|
|
378
380
|
* be authorized by the maker, and `isRootCanceled(maker, root)` must be false.
|
|
@@ -489,7 +491,7 @@ export var EcrecoverRatifierUtils;
|
|
|
489
491
|
* ```
|
|
490
492
|
*/
|
|
491
493
|
async function sign(params) {
|
|
492
|
-
const { tree } =
|
|
494
|
+
const { tree } = Ratifier.normalizeRatifierTree({
|
|
493
495
|
tree: params.tree,
|
|
494
496
|
label: "Ecrecover",
|
|
495
497
|
});
|
|
@@ -697,7 +699,7 @@ export var EcrecoverRatifierUtils;
|
|
|
697
699
|
* ```
|
|
698
700
|
*/
|
|
699
701
|
function ratifierData(params) {
|
|
700
|
-
const { tree } =
|
|
702
|
+
const { tree } = Ratifier.normalizeRatifierTree({
|
|
701
703
|
tree: params.tree,
|
|
702
704
|
label: "Ecrecover",
|
|
703
705
|
});
|
|
@@ -771,7 +773,7 @@ export var EcrecoverRatifierUtils;
|
|
|
771
773
|
* ```
|
|
772
774
|
*/
|
|
773
775
|
async function ratify(params) {
|
|
774
|
-
const { tree } =
|
|
776
|
+
const { tree } = Ratifier.normalizeRatifierTree({
|
|
775
777
|
tree: params.tree,
|
|
776
778
|
label: "Ecrecover",
|
|
777
779
|
});
|
|
@@ -814,13 +816,148 @@ export var EcrecoverRatifierUtils;
|
|
|
814
816
|
account: params.account,
|
|
815
817
|
}));
|
|
816
818
|
}
|
|
819
|
+
const proofs = TreeUtils.buildProofs({
|
|
820
|
+
tree,
|
|
821
|
+
count: tree.offers.length,
|
|
822
|
+
});
|
|
817
823
|
return tree.offers.map((offer, leafIndex) => ({
|
|
818
824
|
offer,
|
|
819
825
|
ratifierData: encodeRatifierData({
|
|
820
826
|
signature,
|
|
821
|
-
...
|
|
827
|
+
...proofs[leafIndex],
|
|
822
828
|
}),
|
|
823
829
|
}));
|
|
824
830
|
}
|
|
825
831
|
EcrecoverRatifierUtils.ratify = ratify;
|
|
826
832
|
})(EcrecoverRatifierUtils || (EcrecoverRatifierUtils = {}));
|
|
833
|
+
/**
|
|
834
|
+
* Tagged-tree API for EcrecoverRatifier with validated portable leaf commitments.
|
|
835
|
+
* Legacy untagged inputs remain available through {@link EcrecoverRatifierUtils}.
|
|
836
|
+
*/
|
|
837
|
+
export var EcrecoverRatifier;
|
|
838
|
+
(function (EcrecoverRatifier) {
|
|
839
|
+
/**
|
|
840
|
+
* Builds Ecrecover signing data from a tagged tree.
|
|
841
|
+
* @param request.tree - Matching tagged tree or portable snapshot; commitments are validated before use.
|
|
842
|
+
* @param request.chainId - Chain defining the EIP-712 domain.
|
|
843
|
+
* @returns EIP-712 domain, type definitions, and offer-tree message.
|
|
844
|
+
* @throws {InvalidTreeError} When the tag, commitments, or root are invalid.
|
|
845
|
+
* @throws {InvalidTreeHeightError} When the descriptor height is unsupported.
|
|
846
|
+
* @example
|
|
847
|
+
* ```ts
|
|
848
|
+
* import { EcrecoverRatifier, type EcrecoverRatifierTypedDataRequest } from "@morpho-org/midnight-sdk";
|
|
849
|
+
* function execute(request: EcrecoverRatifierTypedDataRequest) {
|
|
850
|
+
* return EcrecoverRatifier.typedData(request);
|
|
851
|
+
* }
|
|
852
|
+
* ```
|
|
853
|
+
*/
|
|
854
|
+
function typedData(request) {
|
|
855
|
+
const tree = parseStandardRatifierTree(request.tree, "ecrecover");
|
|
856
|
+
return EcrecoverRatifierUtils.typedData({ ...request, tree });
|
|
857
|
+
}
|
|
858
|
+
EcrecoverRatifier.typedData = typedData;
|
|
859
|
+
/**
|
|
860
|
+
* Computes the signing digest of a tagged Ecrecover tree.
|
|
861
|
+
* @param request.tree - Matching tagged tree or portable snapshot; commitments are validated before use.
|
|
862
|
+
* @param request.chainId - Chain defining the EIP-712 domain.
|
|
863
|
+
* @returns The EIP-712 signing digest.
|
|
864
|
+
* @throws {InvalidTreeError} When the tag, commitments, or root are invalid.
|
|
865
|
+
* @throws {InvalidTreeHeightError} When the descriptor height is unsupported.
|
|
866
|
+
* @example
|
|
867
|
+
* ```ts
|
|
868
|
+
* import { EcrecoverRatifier, type EcrecoverRatifierTypedDataRequest } from "@morpho-org/midnight-sdk";
|
|
869
|
+
* function execute(request: EcrecoverRatifierTypedDataRequest) {
|
|
870
|
+
* return EcrecoverRatifier.digest(request);
|
|
871
|
+
* }
|
|
872
|
+
* ```
|
|
873
|
+
*/
|
|
874
|
+
function digest(request) {
|
|
875
|
+
const tree = parseStandardRatifierTree(request.tree, "ecrecover");
|
|
876
|
+
return EcrecoverRatifierUtils.digest({ ...request, tree });
|
|
877
|
+
}
|
|
878
|
+
EcrecoverRatifier.digest = digest;
|
|
879
|
+
/**
|
|
880
|
+
* Signs a tagged Ecrecover tree using the supplied client and account.
|
|
881
|
+
* @param request.tree - Matching tagged tree or portable snapshot; commitments are validated before use.
|
|
882
|
+
* @param request.account - Maker or authorized signer.
|
|
883
|
+
* @param request.client - Signing client; omit when ratify receives a precomputed signature.
|
|
884
|
+
* @returns A verified hex signature over the tree.
|
|
885
|
+
* @throws {InvalidTreeError} When the tag, commitments, or root are invalid.
|
|
886
|
+
* @throws {InvalidTreeHeightError} When the descriptor height is unsupported.
|
|
887
|
+
* @throws {ChainIdMismatchError} When the signing client's chain differs from the offers.
|
|
888
|
+
* @throws {InvalidTypedDataSignatureError} When the signature does not recover to the supplied account.
|
|
889
|
+
* @example
|
|
890
|
+
* ```ts
|
|
891
|
+
* import { EcrecoverRatifier, type EcrecoverRatifierSignRequest } from "@morpho-org/midnight-sdk";
|
|
892
|
+
* function execute(request: EcrecoverRatifierSignRequest) {
|
|
893
|
+
* return EcrecoverRatifier.sign(request);
|
|
894
|
+
* }
|
|
895
|
+
* ```
|
|
896
|
+
*/
|
|
897
|
+
async function sign(request) {
|
|
898
|
+
const tree = parseStandardRatifierTree(request.tree, "ecrecover");
|
|
899
|
+
return EcrecoverRatifierUtils.sign({ ...request, tree });
|
|
900
|
+
}
|
|
901
|
+
EcrecoverRatifier.sign = sign;
|
|
902
|
+
/**
|
|
903
|
+
* Encodes the signature and proof for one tagged Ecrecover leaf.
|
|
904
|
+
* @param request.tree - Matching tagged tree or portable snapshot; commitments are validated before use.
|
|
905
|
+
* @param request.signature - Tree signature; ratify may instead request one through the supplied client.
|
|
906
|
+
* @param request.leafIndex - Leaf to prove.
|
|
907
|
+
* @returns ABI-encoded ratifier data for the requested leaf.
|
|
908
|
+
* @throws {InvalidTreeError} When the tag, commitments, or root are invalid.
|
|
909
|
+
* @throws {InvalidTreeHeightError} When the descriptor height is unsupported.
|
|
910
|
+
* @throws {InvalidEcrecoverSignatureVError} When a supplied signature has an unsupported recovery value.
|
|
911
|
+
* @example
|
|
912
|
+
* ```ts
|
|
913
|
+
* import { EcrecoverRatifier, type EcrecoverRatifierDataRequest } from "@morpho-org/midnight-sdk";
|
|
914
|
+
* function execute(request: EcrecoverRatifierDataRequest) {
|
|
915
|
+
* return EcrecoverRatifier.ratifierData(request);
|
|
916
|
+
* }
|
|
917
|
+
* ```
|
|
918
|
+
*/
|
|
919
|
+
function ratifierData(request) {
|
|
920
|
+
const tree = parseStandardRatifierTree(request.tree, "ecrecover");
|
|
921
|
+
return EcrecoverRatifierUtils.ratifierData({ ...request, tree });
|
|
922
|
+
}
|
|
923
|
+
EcrecoverRatifier.ratifierData = ratifierData;
|
|
924
|
+
/**
|
|
925
|
+
* Builds payload items from a tagged tree and a verified signature.
|
|
926
|
+
* @param request.tree - Matching tagged tree or portable snapshot; commitments are validated before use.
|
|
927
|
+
* @param request.account - Maker or authorized signer.
|
|
928
|
+
* @param request.client - Signing client; omit when ratify receives a precomputed signature.
|
|
929
|
+
* @param request.signature - Tree signature; ratify may instead request one through the supplied client.
|
|
930
|
+
* @returns One payload item per non-padding offer, including its ratifier data.
|
|
931
|
+
* @throws {InvalidTreeError} When the tag, commitments, or root are invalid.
|
|
932
|
+
* @throws {InvalidTreeHeightError} When the descriptor height is unsupported.
|
|
933
|
+
* @throws {ChainIdMismatchError} When the signing client's chain differs from the offers.
|
|
934
|
+
* @throws {InvalidTypedDataSignatureError} When the signature does not recover to the supplied account.
|
|
935
|
+
* @throws {InvalidEcrecoverSignatureVError} When a supplied signature has an unsupported recovery value.
|
|
936
|
+
* @example
|
|
937
|
+
* ```ts
|
|
938
|
+
* import { EcrecoverRatifier, type EcrecoverRatifierRatifyRequest } from "@morpho-org/midnight-sdk";
|
|
939
|
+
* function execute(request: EcrecoverRatifierRatifyRequest) {
|
|
940
|
+
* return EcrecoverRatifier.ratify(request);
|
|
941
|
+
* }
|
|
942
|
+
* ```
|
|
943
|
+
*/
|
|
944
|
+
async function ratify(request) {
|
|
945
|
+
const tree = parseStandardRatifierTree(request.tree, "ecrecover");
|
|
946
|
+
return EcrecoverRatifierUtils.ratify({ ...request, tree });
|
|
947
|
+
}
|
|
948
|
+
EcrecoverRatifier.ratify = ratify;
|
|
949
|
+
/** {@inheritDoc EcrecoverRatifierUtils.treeTypeHash} */
|
|
950
|
+
EcrecoverRatifier.treeTypeHash = EcrecoverRatifierUtils.treeTypeHash;
|
|
951
|
+
/** {@inheritDoc EcrecoverRatifierUtils.digestForRoot} */
|
|
952
|
+
EcrecoverRatifier.digestForRoot = EcrecoverRatifierUtils.digestForRoot;
|
|
953
|
+
/** {@inheritDoc EcrecoverRatifierUtils.digestRatifierData} */
|
|
954
|
+
EcrecoverRatifier.digestRatifierData = EcrecoverRatifierUtils.digestRatifierData;
|
|
955
|
+
/** {@inheritDoc EcrecoverRatifierUtils.verifyRatifierData} */
|
|
956
|
+
EcrecoverRatifier.verifyRatifierData = EcrecoverRatifierUtils.verifyRatifierData;
|
|
957
|
+
/** {@inheritDoc EcrecoverRatifierUtils.toSignature} */
|
|
958
|
+
EcrecoverRatifier.toSignature = EcrecoverRatifierUtils.toSignature;
|
|
959
|
+
/** {@inheritDoc EcrecoverRatifierUtils.encodeRatifierData} */
|
|
960
|
+
EcrecoverRatifier.encodeRatifierData = EcrecoverRatifierUtils.encodeRatifierData;
|
|
961
|
+
/** {@inheritDoc EcrecoverRatifierUtils.decodeRatifierData} */
|
|
962
|
+
EcrecoverRatifier.decodeRatifierData = EcrecoverRatifierUtils.decodeRatifierData;
|
|
963
|
+
})(EcrecoverRatifier || (EcrecoverRatifier = {}));
|
|
@@ -154,8 +154,11 @@ export declare namespace GroupUtils {
|
|
|
154
154
|
/**
|
|
155
155
|
* Derives the deterministic content-addressed id for a group of offers.
|
|
156
156
|
*
|
|
157
|
-
*
|
|
158
|
-
*
|
|
157
|
+
* Hashes each offer with `group = 0` using the protocol offer hash, sorts
|
|
158
|
+
* those hashes, concatenates them, then keccaks the result. This matches the
|
|
159
|
+
* router for Ecrecover and Setter offers only; RateRatifierV1 and
|
|
160
|
+
* PriceRatifierV1 commit to scheme leaf hashes, so use
|
|
161
|
+
* `RateRatifierV1.groupId` / `PriceRatifierV1.groupId` for those.
|
|
159
162
|
*
|
|
160
163
|
* @param offers - Offers to hash as one group.
|
|
161
164
|
* @returns Content-addressed group id.
|
|
@@ -195,6 +198,56 @@ export declare namespace GroupUtils {
|
|
|
195
198
|
* ```
|
|
196
199
|
*/
|
|
197
200
|
function hash(offers: Iterable<IOffer>): Hash;
|
|
201
|
+
/**
|
|
202
|
+
* Derives a content-addressed group id from ratifier-specific member hashes.
|
|
203
|
+
*
|
|
204
|
+
* This is the ratifier-agnostic core of {@link hash}: each member hash must
|
|
205
|
+
* commit the offer with `group = 0` under the scheme the offer is ratified
|
|
206
|
+
* with (the protocol offer hash for Ecrecover/Setter, the zero-group leaf
|
|
207
|
+
* hash for `RateRatifierV1`/`PriceRatifierV1`). Hashes are lowercased,
|
|
208
|
+
* sorted, concatenated, then keccak'd, so neither member order nor hex
|
|
209
|
+
* casing affects the id.
|
|
210
|
+
*
|
|
211
|
+
* @param memberHashes - Zero-group member hashes of one consumption group.
|
|
212
|
+
* @returns Content-addressed group id.
|
|
213
|
+
* @throws {InvalidOfferGroupError} when `memberHashes` is empty.
|
|
214
|
+
* @example
|
|
215
|
+
* ```ts
|
|
216
|
+
* import { GroupUtils, Offer, RateRatifierV1 } from "@morpho-org/midnight-sdk";
|
|
217
|
+
* import { zeroAddress } from "viem";
|
|
218
|
+
*
|
|
219
|
+
* const offer = Offer.create({
|
|
220
|
+
* market: {
|
|
221
|
+
* chainId: 8453,
|
|
222
|
+
* midnight: "0x0000000000000000000000000000000000001000",
|
|
223
|
+
* loanToken: "0x0000000000000000000000000000000000006000",
|
|
224
|
+
* collateralParams: [
|
|
225
|
+
* {
|
|
226
|
+
* token: "0x0000000000000000000000000000000000007000",
|
|
227
|
+
* lltv: 770000000000000000n,
|
|
228
|
+
* liquidationCursor: 250000000000000000n,
|
|
229
|
+
* oracle: "0x0000000000000000000000000000000000008000",
|
|
230
|
+
* },
|
|
231
|
+
* ],
|
|
232
|
+
* maturity: 54_000n,
|
|
233
|
+
* rcfThreshold: 0n,
|
|
234
|
+
* enterGate: zeroAddress,
|
|
235
|
+
* liquidatorGate: zeroAddress,
|
|
236
|
+
* },
|
|
237
|
+
* buy: true,
|
|
238
|
+
* maker: "0x0000000000000000000000000000000000009000",
|
|
239
|
+
* tick: 5_000n,
|
|
240
|
+
* expiry: 3_600n,
|
|
241
|
+
* ratifier: "0x000000000000000000000000000000000000a111",
|
|
242
|
+
* maxUnits: 100n,
|
|
243
|
+
* });
|
|
244
|
+
* const id = GroupUtils.hashMembers([
|
|
245
|
+
* RateRatifierV1.memberHash({ offer, rate: 50_000_000_000_000_000n }),
|
|
246
|
+
* ]);
|
|
247
|
+
* console.log(id);
|
|
248
|
+
* ```
|
|
249
|
+
*/
|
|
250
|
+
function hashMembers(memberHashes: Iterable<Hash>): Hash;
|
|
198
251
|
/**
|
|
199
252
|
* Converts a group into ABI-compatible offers carrying the derived group id.
|
|
200
253
|
*
|
|
@@ -73,8 +73,11 @@ export var GroupUtils;
|
|
|
73
73
|
/**
|
|
74
74
|
* Derives the deterministic content-addressed id for a group of offers.
|
|
75
75
|
*
|
|
76
|
-
*
|
|
77
|
-
*
|
|
76
|
+
* Hashes each offer with `group = 0` using the protocol offer hash, sorts
|
|
77
|
+
* those hashes, concatenates them, then keccaks the result. This matches the
|
|
78
|
+
* router for Ecrecover and Setter offers only; RateRatifierV1 and
|
|
79
|
+
* PriceRatifierV1 commit to scheme leaf hashes, so use
|
|
80
|
+
* `RateRatifierV1.groupId` / `PriceRatifierV1.groupId` for those.
|
|
78
81
|
*
|
|
79
82
|
* @param offers - Offers to hash as one group.
|
|
80
83
|
* @returns Content-addressed group id.
|
|
@@ -118,11 +121,67 @@ export var GroupUtils;
|
|
|
118
121
|
if (offerInputs.length === 0) {
|
|
119
122
|
throw new InvalidOfferGroupError("Provide at least one offer in the group.");
|
|
120
123
|
}
|
|
121
|
-
|
|
122
|
-
const sorted = offerHashes.length > 1 ? [...offerHashes].sort() : offerHashes;
|
|
123
|
-
return keccak256(concat(sorted));
|
|
124
|
+
return hashMembers(offerInputs.map((offer) => OfferUtils.groupHash(offer)));
|
|
124
125
|
}
|
|
125
126
|
GroupUtils.hash = hash;
|
|
127
|
+
/**
|
|
128
|
+
* Derives a content-addressed group id from ratifier-specific member hashes.
|
|
129
|
+
*
|
|
130
|
+
* This is the ratifier-agnostic core of {@link hash}: each member hash must
|
|
131
|
+
* commit the offer with `group = 0` under the scheme the offer is ratified
|
|
132
|
+
* with (the protocol offer hash for Ecrecover/Setter, the zero-group leaf
|
|
133
|
+
* hash for `RateRatifierV1`/`PriceRatifierV1`). Hashes are lowercased,
|
|
134
|
+
* sorted, concatenated, then keccak'd, so neither member order nor hex
|
|
135
|
+
* casing affects the id.
|
|
136
|
+
*
|
|
137
|
+
* @param memberHashes - Zero-group member hashes of one consumption group.
|
|
138
|
+
* @returns Content-addressed group id.
|
|
139
|
+
* @throws {InvalidOfferGroupError} when `memberHashes` is empty.
|
|
140
|
+
* @example
|
|
141
|
+
* ```ts
|
|
142
|
+
* import { GroupUtils, Offer, RateRatifierV1 } from "@morpho-org/midnight-sdk";
|
|
143
|
+
* import { zeroAddress } from "viem";
|
|
144
|
+
*
|
|
145
|
+
* const offer = Offer.create({
|
|
146
|
+
* market: {
|
|
147
|
+
* chainId: 8453,
|
|
148
|
+
* midnight: "0x0000000000000000000000000000000000001000",
|
|
149
|
+
* loanToken: "0x0000000000000000000000000000000000006000",
|
|
150
|
+
* collateralParams: [
|
|
151
|
+
* {
|
|
152
|
+
* token: "0x0000000000000000000000000000000000007000",
|
|
153
|
+
* lltv: 770000000000000000n,
|
|
154
|
+
* liquidationCursor: 250000000000000000n,
|
|
155
|
+
* oracle: "0x0000000000000000000000000000000000008000",
|
|
156
|
+
* },
|
|
157
|
+
* ],
|
|
158
|
+
* maturity: 54_000n,
|
|
159
|
+
* rcfThreshold: 0n,
|
|
160
|
+
* enterGate: zeroAddress,
|
|
161
|
+
* liquidatorGate: zeroAddress,
|
|
162
|
+
* },
|
|
163
|
+
* buy: true,
|
|
164
|
+
* maker: "0x0000000000000000000000000000000000009000",
|
|
165
|
+
* tick: 5_000n,
|
|
166
|
+
* expiry: 3_600n,
|
|
167
|
+
* ratifier: "0x000000000000000000000000000000000000a111",
|
|
168
|
+
* maxUnits: 100n,
|
|
169
|
+
* });
|
|
170
|
+
* const id = GroupUtils.hashMembers([
|
|
171
|
+
* RateRatifierV1.memberHash({ offer, rate: 50_000_000_000_000_000n }),
|
|
172
|
+
* ]);
|
|
173
|
+
* console.log(id);
|
|
174
|
+
* ```
|
|
175
|
+
*/
|
|
176
|
+
function hashMembers(memberHashes) {
|
|
177
|
+
const hashes = Array.from(memberHashes, (h) => h.toLowerCase());
|
|
178
|
+
if (hashes.length === 0) {
|
|
179
|
+
throw new InvalidOfferGroupError("Provide at least one member hash in the group.");
|
|
180
|
+
}
|
|
181
|
+
const sorted = hashes.length > 1 ? [...hashes].sort() : hashes;
|
|
182
|
+
return keccak256(concat(sorted));
|
|
183
|
+
}
|
|
184
|
+
GroupUtils.hashMembers = hashMembers;
|
|
126
185
|
/**
|
|
127
186
|
* Converts a group into ABI-compatible offers carrying the derived group id.
|
|
128
187
|
*
|
|
@@ -13,12 +13,12 @@ export declare namespace Payload {
|
|
|
13
13
|
* `ratifierData` blob a taker hands to `Midnight.take(..., ratifierData)`.
|
|
14
14
|
*
|
|
15
15
|
* `ratifierData` is owned by the ratifier scheme the maker used (e.g.
|
|
16
|
-
* `
|
|
16
|
+
* `EcrecoverRatifier.ratifierData`). The payload codec treats it as
|
|
17
17
|
* opaque bytes — simulators that only need to forward `ratifierData` can
|
|
18
18
|
* stay completely ratifier-agnostic.
|
|
19
19
|
*
|
|
20
|
-
* Build items with `
|
|
21
|
-
* `
|
|
20
|
+
* Build items with `EcrecoverRatifier.ratify` or
|
|
21
|
+
* `SetterRatifier.ratify` after the tree is signed or approved, then pass
|
|
22
22
|
* the items to `Payload.encode` for publication.
|
|
23
23
|
*
|
|
24
24
|
* @example
|