@sig-net/midnight 0.18.0 → 0.20.0-rc.1
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/README.md +42 -2
- package/dist/abi-serde.d.ts +32 -30
- package/dist/abi-serde.d.ts.map +1 -1
- package/dist/abi-serde.js +139 -75
- package/dist/abi-serde.js.map +1 -1
- package/dist/byte-codecs.d.ts +62 -0
- package/dist/byte-codecs.d.ts.map +1 -0
- package/dist/byte-codecs.js +116 -0
- package/dist/byte-codecs.js.map +1 -0
- package/dist/compact-descriptors.d.ts +89 -0
- package/dist/compact-descriptors.d.ts.map +1 -0
- package/dist/compact-descriptors.js +139 -0
- package/dist/compact-descriptors.js.map +1 -0
- package/dist/constants.d.ts +18 -43
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +19 -45
- package/dist/constants.js.map +1 -1
- package/dist/ecdsa-attestation.d.ts +49 -97
- package/dist/ecdsa-attestation.d.ts.map +1 -1
- package/dist/ecdsa-attestation.js +78 -142
- package/dist/ecdsa-attestation.js.map +1 -1
- package/dist/epsilon-derivation.d.ts +24 -31
- package/dist/epsilon-derivation.d.ts.map +1 -1
- package/dist/epsilon-derivation.js +52 -62
- package/dist/epsilon-derivation.js.map +1 -1
- package/dist/index.d.ts +10 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +17 -8
- package/dist/index.js.map +1 -1
- package/dist/managed/compiler/contract-info.json +0 -22
- package/dist/managed/compiler/contract-manifest.json +8 -8
- package/dist/managed/contract/index.d.ts +0 -3
- package/dist/managed/contract/index.js +65 -80
- package/dist/managed/contract/index.js.map +1 -1
- package/dist/raw-contract-state.d.ts +25 -0
- package/dist/raw-contract-state.d.ts.map +1 -0
- package/dist/raw-contract-state.js +52 -0
- package/dist/raw-contract-state.js.map +1 -0
- package/dist/signature-requests-state-reader.d.ts +18 -44
- package/dist/signature-requests-state-reader.d.ts.map +1 -1
- package/dist/signature-requests-state-reader.js +82 -146
- package/dist/signature-requests-state-reader.js.map +1 -1
- package/dist/signature-response-verification.d.ts +9 -8
- package/dist/signature-response-verification.d.ts.map +1 -1
- package/dist/signature-response-verification.js +20 -17
- package/dist/signature-response-verification.js.map +1 -1
- package/dist/signet-contract-events.d.ts +56 -64
- package/dist/signet-contract-events.d.ts.map +1 -1
- package/dist/signet-contract-events.js +46 -48
- package/dist/signet-contract-events.js.map +1 -1
- package/dist/signet-evtype2tx-record-decoding.d.ts +18 -0
- package/dist/signet-evtype2tx-record-decoding.d.ts.map +1 -0
- package/dist/signet-evtype2tx-record-decoding.js +97 -0
- package/dist/signet-evtype2tx-record-decoding.js.map +1 -0
- package/dist/signet-evtype2tx-requests.d.ts +43 -87
- package/dist/signet-evtype2tx-requests.d.ts.map +1 -1
- package/dist/signet-evtype2tx-requests.js +59 -130
- package/dist/signet-evtype2tx-requests.js.map +1 -1
- package/dist/signet-request-id.d.ts +14 -0
- package/dist/signet-request-id.d.ts.map +1 -0
- package/dist/signet-request-id.js +27 -0
- package/dist/signet-request-id.js.map +1 -0
- package/dist/signet-request-response-reader.d.ts +34 -56
- package/dist/signet-request-response-reader.d.ts.map +1 -1
- package/dist/signet-request-response-reader.js +56 -68
- package/dist/signet-request-response-reader.js.map +1 -1
- package/dist/signet-requests.d.ts +28 -92
- package/dist/signet-requests.d.ts.map +1 -1
- package/dist/signet-requests.js +39 -141
- package/dist/signet-requests.js.map +1 -1
- package/dist/testing.d.ts +3 -0
- package/dist/testing.d.ts.map +1 -0
- package/dist/testing.js +20 -0
- package/dist/testing.js.map +1 -0
- package/package.json +13 -4
- package/src/Signet.compact +110 -171
- package/src/circuits.compact +9 -16
- package/dist/signature-state-reading.d.ts +0 -43
- package/dist/signature-state-reading.d.ts.map +0 -1
- package/dist/signature-state-reading.js +0 -74
- package/dist/signature-state-reading.js.map +0 -1
- package/dist/signet-request-feed.d.ts +0 -126
- package/dist/signet-request-feed.d.ts.map +0 -1
- package/dist/signet-request-feed.js +0 -216
- package/dist/signet-request-feed.js.map +0 -1
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Render bytes as a lowercase hex string, no `0x` prefix.
|
|
3
|
+
*
|
|
4
|
+
* @param bytes - The bytes to render.
|
|
5
|
+
* @returns Lowercase hex, two chars per byte.
|
|
6
|
+
*/
|
|
7
|
+
export declare function bytesToHex(bytes: Uint8Array): string;
|
|
8
|
+
/**
|
|
9
|
+
* Strip an optional `0x`/`0X` prefix from a hex string.
|
|
10
|
+
*
|
|
11
|
+
* @param hex - A hex string, with or without a `0x` prefix.
|
|
12
|
+
* @returns The bare hex digits.
|
|
13
|
+
*/
|
|
14
|
+
export declare function stripHexPrefix(hex: string): string;
|
|
15
|
+
/**
|
|
16
|
+
* Decode a hex string into bytes: the inverse of {@link bytesToHex}.
|
|
17
|
+
*
|
|
18
|
+
* @param hex - An even number of hex digits, with or without a `0x` prefix.
|
|
19
|
+
* @returns The decoded bytes.
|
|
20
|
+
* @throws {Error} If the digits are odd-length or not all hex: lenient parsing
|
|
21
|
+
* would return plausible-looking wrong bytes.
|
|
22
|
+
*/
|
|
23
|
+
export declare function hexToBytes(hex: string): Uint8Array;
|
|
24
|
+
/** BLS12-381 scalar field order (the Compact `Field` type modulus). */
|
|
25
|
+
export declare const BLS_ORDER = 52435875175126190479447740508185965837690552500527637822603658699938581184513n;
|
|
26
|
+
/**
|
|
27
|
+
* Little-endian bytes to a bigint: the byte order Compact's
|
|
28
|
+
* `Bytes<32> as Field` / `as Secp256k1Scalar` casts read.
|
|
29
|
+
*
|
|
30
|
+
* @param bytes - Little-endian byte array.
|
|
31
|
+
* @returns The decoded non-negative integer.
|
|
32
|
+
*/
|
|
33
|
+
export declare function bytesToBigint(bytes: Uint8Array): bigint;
|
|
34
|
+
/**
|
|
35
|
+
* A bigint to exactly 32 little-endian bytes: the inverse of
|
|
36
|
+
* {@link bytesToBigint}. Non-negative values encode raw (the full 32-byte
|
|
37
|
+
* range, so secp256k1 scalars above {@link BLS_ORDER} fit). Negative values
|
|
38
|
+
* are interpreted in the BLS scalar field, so their domain is
|
|
39
|
+
* `[-BLS_ORDER, 0)`.
|
|
40
|
+
*
|
|
41
|
+
* @param n - The integer to encode.
|
|
42
|
+
* @returns The 32-byte little-endian encoding.
|
|
43
|
+
* @throws {Error} If the value is below `-BLS_ORDER` or does not fit 32 bytes.
|
|
44
|
+
*/
|
|
45
|
+
export declare function bigintToBytes32(n: bigint): Uint8Array;
|
|
46
|
+
/**
|
|
47
|
+
* Big-endian (SEC1) bytes to a bigint: the byte order stored signatures use.
|
|
48
|
+
*
|
|
49
|
+
* @param bytes - Big-endian byte array.
|
|
50
|
+
* @returns The decoded non-negative integer.
|
|
51
|
+
*/
|
|
52
|
+
export declare function bytesToBigintBE(bytes: Uint8Array): bigint;
|
|
53
|
+
/**
|
|
54
|
+
* A bigint to exactly 32 big-endian (SEC1) bytes: the inverse of
|
|
55
|
+
* {@link bytesToBigintBE}.
|
|
56
|
+
*
|
|
57
|
+
* @param value - The non-negative integer to encode.
|
|
58
|
+
* @returns The 32-byte big-endian encoding.
|
|
59
|
+
* @throws {Error} If the value is negative or does not fit 32 bytes.
|
|
60
|
+
*/
|
|
61
|
+
export declare function bigintToBytes32BE(value: bigint): Uint8Array;
|
|
62
|
+
//# sourceMappingURL=byte-codecs.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"byte-codecs.d.ts","sourceRoot":"","sources":["../src/byte-codecs.ts"],"names":[],"mappings":"AAKA;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAEpD;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAElD;AAED;;;;;;;GAOG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU,CAUlD;AAED,uEAAuE;AACvE,eAAO,MAAM,SAAS,iFAC0D,CAAC;AAEjF;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAQvD;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,eAAe,CAAC,CAAC,EAAE,MAAM,GAAG,UAAU,CAWrD;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAMzD;AAED;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,GAAG,UAAU,CAW3D"}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
// Byte codecs shared across the package: hex string rendering/parsing and
|
|
2
|
+
// fixed-width integer encodings in both byte orders. Big-endian is the SEC1
|
|
3
|
+
// order stored signatures and ABI words use, little-endian is the order
|
|
4
|
+
// Compact's `Bytes<32> as Field` / `as Secp256k1Scalar` casts read.
|
|
5
|
+
/**
|
|
6
|
+
* Render bytes as a lowercase hex string, no `0x` prefix.
|
|
7
|
+
*
|
|
8
|
+
* @param bytes - The bytes to render.
|
|
9
|
+
* @returns Lowercase hex, two chars per byte.
|
|
10
|
+
*/
|
|
11
|
+
export function bytesToHex(bytes) {
|
|
12
|
+
return Array.from(bytes, (b) => b.toString(16).padStart(2, "0")).join("");
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Strip an optional `0x`/`0X` prefix from a hex string.
|
|
16
|
+
*
|
|
17
|
+
* @param hex - A hex string, with or without a `0x` prefix.
|
|
18
|
+
* @returns The bare hex digits.
|
|
19
|
+
*/
|
|
20
|
+
export function stripHexPrefix(hex) {
|
|
21
|
+
return hex.startsWith("0x") || hex.startsWith("0X") ? hex.slice(2) : hex;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Decode a hex string into bytes: the inverse of {@link bytesToHex}.
|
|
25
|
+
*
|
|
26
|
+
* @param hex - An even number of hex digits, with or without a `0x` prefix.
|
|
27
|
+
* @returns The decoded bytes.
|
|
28
|
+
* @throws {Error} If the digits are odd-length or not all hex: lenient parsing
|
|
29
|
+
* would return plausible-looking wrong bytes.
|
|
30
|
+
*/
|
|
31
|
+
export function hexToBytes(hex) {
|
|
32
|
+
const digits = stripHexPrefix(hex);
|
|
33
|
+
if (digits.length % 2 !== 0 || !/^[0-9a-fA-F]*$/.test(digits)) {
|
|
34
|
+
throw new Error(`not a hex byte string: "${hex}"`);
|
|
35
|
+
}
|
|
36
|
+
const out = new Uint8Array(digits.length >> 1);
|
|
37
|
+
for (let i = 0; i < out.length; i++) {
|
|
38
|
+
out[i] = Number.parseInt(digits.slice(2 * i, 2 * i + 2), 16);
|
|
39
|
+
}
|
|
40
|
+
return out;
|
|
41
|
+
}
|
|
42
|
+
/** BLS12-381 scalar field order (the Compact `Field` type modulus). */
|
|
43
|
+
export const BLS_ORDER = 52435875175126190479447740508185965837690552500527637822603658699938581184513n;
|
|
44
|
+
/**
|
|
45
|
+
* Little-endian bytes to a bigint: the byte order Compact's
|
|
46
|
+
* `Bytes<32> as Field` / `as Secp256k1Scalar` casts read.
|
|
47
|
+
*
|
|
48
|
+
* @param bytes - Little-endian byte array.
|
|
49
|
+
* @returns The decoded non-negative integer.
|
|
50
|
+
*/
|
|
51
|
+
export function bytesToBigint(bytes) {
|
|
52
|
+
let result = 0n;
|
|
53
|
+
let shift = 0n;
|
|
54
|
+
for (const byte of bytes) {
|
|
55
|
+
result |= BigInt(byte) << shift;
|
|
56
|
+
shift += 8n;
|
|
57
|
+
}
|
|
58
|
+
return result;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* A bigint to exactly 32 little-endian bytes: the inverse of
|
|
62
|
+
* {@link bytesToBigint}. Non-negative values encode raw (the full 32-byte
|
|
63
|
+
* range, so secp256k1 scalars above {@link BLS_ORDER} fit). Negative values
|
|
64
|
+
* are interpreted in the BLS scalar field, so their domain is
|
|
65
|
+
* `[-BLS_ORDER, 0)`.
|
|
66
|
+
*
|
|
67
|
+
* @param n - The integer to encode.
|
|
68
|
+
* @returns The 32-byte little-endian encoding.
|
|
69
|
+
* @throws {Error} If the value is below `-BLS_ORDER` or does not fit 32 bytes.
|
|
70
|
+
*/
|
|
71
|
+
export function bigintToBytes32(n) {
|
|
72
|
+
if (n < -BLS_ORDER || n >= 1n << 256n) {
|
|
73
|
+
throw new Error(`value does not fit 32 little-endian bytes: ${String(n)}`);
|
|
74
|
+
}
|
|
75
|
+
const buf = new Uint8Array(32);
|
|
76
|
+
let v = n < 0n ? n + BLS_ORDER : n;
|
|
77
|
+
for (let i = 0; i < 32; i++) {
|
|
78
|
+
buf[i] = Number(v & 0xffn);
|
|
79
|
+
v >>= 8n;
|
|
80
|
+
}
|
|
81
|
+
return buf;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Big-endian (SEC1) bytes to a bigint: the byte order stored signatures use.
|
|
85
|
+
*
|
|
86
|
+
* @param bytes - Big-endian byte array.
|
|
87
|
+
* @returns The decoded non-negative integer.
|
|
88
|
+
*/
|
|
89
|
+
export function bytesToBigintBE(bytes) {
|
|
90
|
+
let value = 0n;
|
|
91
|
+
for (const byte of bytes) {
|
|
92
|
+
value = (value << 8n) | BigInt(byte);
|
|
93
|
+
}
|
|
94
|
+
return value;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* A bigint to exactly 32 big-endian (SEC1) bytes: the inverse of
|
|
98
|
+
* {@link bytesToBigintBE}.
|
|
99
|
+
*
|
|
100
|
+
* @param value - The non-negative integer to encode.
|
|
101
|
+
* @returns The 32-byte big-endian encoding.
|
|
102
|
+
* @throws {Error} If the value is negative or does not fit 32 bytes.
|
|
103
|
+
*/
|
|
104
|
+
export function bigintToBytes32BE(value) {
|
|
105
|
+
if (value < 0n || value >= 1n << 256n) {
|
|
106
|
+
throw new Error(`value does not fit 32 big-endian bytes: ${String(value)}`);
|
|
107
|
+
}
|
|
108
|
+
const out = new Uint8Array(32);
|
|
109
|
+
let v = value;
|
|
110
|
+
for (let i = 31; i >= 0; i--) {
|
|
111
|
+
out[i] = Number(v & 0xffn);
|
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CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,eAAe,CAAC,KAAiB;IAC/C,IAAI,KAAK,GAAG,EAAE,CAAC;IACf,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,KAAK,GAAG,CAAC,KAAK,IAAI,EAAE,CAAC,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC;IACvC,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,iBAAiB,CAAC,KAAa;IAC7C,IAAI,KAAK,GAAG,EAAE,IAAI,KAAK,IAAI,EAAE,IAAI,IAAI,EAAE,CAAC;QACtC,MAAM,IAAI,KAAK,CAAC,2CAA2C,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;IAC9E,CAAC;IACD,MAAM,GAAG,GAAG,IAAI,UAAU,CAAC,EAAE,CAAC,CAAC;IAC/B,IAAI,CAAC,GAAG,KAAK,CAAC;IACd,KAAK,IAAI,CAAC,GAAG,EAAE,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;QAC7B,GAAG,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC;QAC3B,CAAC,KAAK,EAAE,CAAC;IACX,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC"}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { type AlignedValue, type CompactType, CompactTypeBytes, CompactTypeUnsignedInteger } from "@midnight-ntwrk/compact-runtime";
|
|
2
|
+
/** Descriptor of a Compact `Bytes<4>`. */
|
|
3
|
+
export declare const BYTES_4: CompactTypeBytes;
|
|
4
|
+
/** Descriptor of a Compact `Bytes<20>`. */
|
|
5
|
+
export declare const BYTES_20: CompactTypeBytes;
|
|
6
|
+
/** Descriptor of a Compact `Bytes<32>`. */
|
|
7
|
+
export declare const BYTES_32: CompactTypeBytes;
|
|
8
|
+
/** Descriptor of a Compact `Bytes<64>`. */
|
|
9
|
+
export declare const BYTES_64: CompactTypeBytes;
|
|
10
|
+
/** Descriptor of a Compact `Uint<8>`. */
|
|
11
|
+
export declare const UINT_8: CompactTypeUnsignedInteger;
|
|
12
|
+
/** Descriptor of a Compact `Uint<16>`. */
|
|
13
|
+
export declare const UINT_16: CompactTypeUnsignedInteger;
|
|
14
|
+
/** Descriptor of a Compact `Uint<64>`. */
|
|
15
|
+
export declare const UINT_64: CompactTypeUnsignedInteger;
|
|
16
|
+
/** Descriptor of a Compact `Uint<128>`. */
|
|
17
|
+
export declare const UINT_128: CompactTypeUnsignedInteger;
|
|
18
|
+
/**
|
|
19
|
+
* A Midnight contract address as the generated code represents it in struct
|
|
20
|
+
* fields (Compact `ContractAddress`): a single-field wrapper around the raw
|
|
21
|
+
* 32 address bytes.
|
|
22
|
+
*/
|
|
23
|
+
export interface ContractAddress {
|
|
24
|
+
bytes: Uint8Array;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Descriptor of a Compact `ContractAddress` struct field: a single-field
|
|
28
|
+
* `{ bytes: Bytes<32> }` wrapper, exactly as the compiler generates it.
|
|
29
|
+
*/
|
|
30
|
+
export declare const CONTRACT_ADDRESS: CompactType<ContractAddress>;
|
|
31
|
+
/**
|
|
32
|
+
* Compact's standard-library `Maybe<T>` as the compiler generates it: a
|
|
33
|
+
* plain struct. Even when `is_some` is false, `value` carries a full
|
|
34
|
+
* default-valued `T` (so vector capacities remain inferable).
|
|
35
|
+
*/
|
|
36
|
+
export interface Maybe<T> {
|
|
37
|
+
is_some: boolean;
|
|
38
|
+
value: T;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Build the runtime descriptor of a Compact struct from its per-field
|
|
42
|
+
* descriptors. Field ORDER is the encoding order and must match the Compact
|
|
43
|
+
* struct declaration order: object literals preserve insertion order for
|
|
44
|
+
* string keys, so pass fields in declaration order.
|
|
45
|
+
*
|
|
46
|
+
* @param fields - One runtime descriptor per struct field, in declaration order.
|
|
47
|
+
* @returns The composed struct descriptor.
|
|
48
|
+
*/
|
|
49
|
+
export declare function compactStructDescriptor<T extends object>(fields: {
|
|
50
|
+
readonly [K in keyof T]-?: CompactType<T[K]>;
|
|
51
|
+
}): CompactType<T>;
|
|
52
|
+
/**
|
|
53
|
+
* Descriptor of Compact's standard-library `Maybe<T>`: the compiler
|
|
54
|
+
* generates it as the struct `{ is_some: Boolean, value: T }`.
|
|
55
|
+
*
|
|
56
|
+
* @param inner - Descriptor of the wrapped type.
|
|
57
|
+
* @returns The Maybe struct descriptor.
|
|
58
|
+
*/
|
|
59
|
+
export declare function compactMaybeDescriptor<T>(inner: CompactType<T>): CompactType<Maybe<T>>;
|
|
60
|
+
/**
|
|
61
|
+
* Decode ONE whole stored value with a descriptor. `fromValue` is a cursor:
|
|
62
|
+
* it consumes atoms from the front of the array it is handed and ignores
|
|
63
|
+
* whatever remains, which is right for descriptors chained mid-struct but
|
|
64
|
+
* wrong for a complete key, cell or payload: called directly it either
|
|
65
|
+
* mutates live state (no copy) or accepts trailing atoms the descriptor
|
|
66
|
+
* never read (copy, no length check). This wrapper owns the copy and rejects
|
|
67
|
+
* leftovers, so a stored shape that has outgrown its descriptor fails loudly
|
|
68
|
+
* instead of decoding a stale prefix.
|
|
69
|
+
*
|
|
70
|
+
* @param type - The descriptor to decode with.
|
|
71
|
+
* @param atoms - The complete stored value. Never mutated.
|
|
72
|
+
* @param what - Error-message subject.
|
|
73
|
+
* @returns The decoded value.
|
|
74
|
+
* @throws {Error} If the descriptor rejects the atoms, or atoms remain after
|
|
75
|
+
* it has consumed its fill.
|
|
76
|
+
*/
|
|
77
|
+
export declare function decodeExactly<T>(type: CompactType<T>, atoms: readonly Uint8Array[], what: string): T;
|
|
78
|
+
/**
|
|
79
|
+
* The declared width of each atom. Signet declares only `Bytes` atoms, so a
|
|
80
|
+
* widthless or nested segment is refused rather than assigned a width.
|
|
81
|
+
*
|
|
82
|
+
* @param cell - The record cell as stored.
|
|
83
|
+
* @param what - Error-message subject.
|
|
84
|
+
* @returns One declared byte width per atom.
|
|
85
|
+
* @throws {Error} If the alignment and value lengths disagree or a segment is
|
|
86
|
+
* not a `Bytes` atom.
|
|
87
|
+
*/
|
|
88
|
+
export declare function declaredWidths(cell: AlignedValue, what: string): number[];
|
|
89
|
+
//# sourceMappingURL=compact-descriptors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compact-descriptors.d.ts","sourceRoot":"","sources":["../src/compact-descriptors.ts"],"names":[],"mappings":"AAyBA,OAAO,EACL,KAAK,YAAY,EACjB,KAAK,WAAW,EAEhB,gBAAgB,EAChB,0BAA0B,EAC3B,MAAM,iCAAiC,CAAC;AAKzC,0CAA0C;AAC1C,eAAO,MAAM,OAAO,kBAA0B,CAAC;AAC/C,2CAA2C;AAC3C,eAAO,MAAM,QAAQ,kBAA2B,CAAC;AACjD,2CAA2C;AAC3C,eAAO,MAAM,QAAQ,kBAA2B,CAAC;AACjD,2CAA2C;AAC3C,eAAO,MAAM,QAAQ,kBAA2B,CAAC;AACjD,yCAAyC;AACzC,eAAO,MAAM,MAAM,4BAAmD,CAAC;AACvE,0CAA0C;AAC1C,eAAO,MAAM,OAAO,4BAAoD,CAAC;AACzE,0CAA0C;AAC1C,eAAO,MAAM,OAAO,4BAAoD,CAAC;AACzE,2CAA2C;AAC3C,eAAO,MAAM,QAAQ,4BAAsD,CAAC;AAE5E;;;;GAIG;AACH,MAAM,WAAW,eAAe;IAC9B,KAAK,EAAE,UAAU,CAAC;CACnB;AAED;;;GAGG;AACH,eAAO,MAAM,gBAAgB,EAAE,WAAW,CAAC,eAAe,CAIzD,CAAC;AAEF;;;;GAIG;AACH,MAAM,WAAW,KAAK,CAAC,CAAC;IACtB,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,EAAE,CAAC,CAAC;CACV;AAED;;;;;;;;GAQG;AACH,wBAAgB,uBAAuB,CAAC,CAAC,SAAS,MAAM,EAAE,MAAM,EAAE;IAChE,QAAQ,EAAE,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,GAAG,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;CAC7C,GAAG,WAAW,CAAC,CAAC,CAAC,CAgBjB;AAED;;;;;;GAMG;AACH,wBAAgB,sBAAsB,CAAC,CAAC,EAAE,KAAK,EAAE,WAAW,CAAC,CAAC,CAAC,GAAG,WAAW,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAKtF;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,aAAa,CAAC,CAAC,EAC7B,IAAI,EAAE,WAAW,CAAC,CAAC,CAAC,EACpB,KAAK,EAAE,SAAS,UAAU,EAAE,EAC5B,IAAI,EAAE,MAAM,GACX,CAAC,CASH;AAED;;;;;;;;;GASG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAoBzE"}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
// Compact-generic runtime descriptor toolkit: compact-runtime `CompactType`
|
|
2
|
+
// codecs (alignment/toValue/fromValue) at the same literals the compiler
|
|
3
|
+
// emits, composed into the signet record descriptors by the request modules.
|
|
4
|
+
// They exist so the package can (a) decode raw state cells of ANY requester
|
|
5
|
+
// contract discovered at runtime and (b) serialize a record byte-identically
|
|
6
|
+
// to the circuits' keccak256 preimage, and they exist HERE only because the
|
|
7
|
+
// Midnight libraries expose no supported equivalent:
|
|
8
|
+
// - A compiled contract module (`src/managed/`) builds one such codec per
|
|
9
|
+
// ledger type but keeps them module-private, exporting only `ledger()`,
|
|
10
|
+
// which decodes the FULL state of the one contract it was compiled from.
|
|
11
|
+
// Signet readers hold neither that contract's compiled module nor its
|
|
12
|
+
// full state: just a cell.
|
|
13
|
+
// - `@midnight-ntwrk/compact-runtime` exports the primitive codec classes
|
|
14
|
+
// (`CompactTypeBytes`, `CompactTypeUnsignedInteger`, ...) but no struct
|
|
15
|
+
// composer and no `Maybe` descriptor, and documents its own pre-built
|
|
16
|
+
// instances (`Bytes32Descriptor`, `ContractAddressDescriptor`, ...) as
|
|
17
|
+
// "not intended for direct consumption".
|
|
18
|
+
// Delete each piece of this file the moment compact-runtime exports a
|
|
19
|
+
// supported equivalent.
|
|
20
|
+
//
|
|
21
|
+
// These are NOT the `CompactType` schema types of @sig-net/midnight-serde
|
|
22
|
+
// (that package describes the `serialize<T, N>` wire format, a different
|
|
23
|
+
// layer). Package-internal: consumers use the reader/request functions built
|
|
24
|
+
// on top, never these directly.
|
|
25
|
+
import { CompactTypeBoolean, CompactTypeBytes, CompactTypeUnsignedInteger, } from "@midnight-ntwrk/compact-runtime";
|
|
26
|
+
// Runtime descriptors of the Compact base types, at the same literals the
|
|
27
|
+
// compiler emits.
|
|
28
|
+
/** Descriptor of a Compact `Bytes<4>`. */
|
|
29
|
+
export const BYTES_4 = new CompactTypeBytes(4);
|
|
30
|
+
/** Descriptor of a Compact `Bytes<20>`. */
|
|
31
|
+
export const BYTES_20 = new CompactTypeBytes(20);
|
|
32
|
+
/** Descriptor of a Compact `Bytes<32>`. */
|
|
33
|
+
export const BYTES_32 = new CompactTypeBytes(32);
|
|
34
|
+
/** Descriptor of a Compact `Bytes<64>`. */
|
|
35
|
+
export const BYTES_64 = new CompactTypeBytes(64);
|
|
36
|
+
/** Descriptor of a Compact `Uint<8>`. */
|
|
37
|
+
export const UINT_8 = new CompactTypeUnsignedInteger(2n ** 8n - 1n, 1);
|
|
38
|
+
/** Descriptor of a Compact `Uint<16>`. */
|
|
39
|
+
export const UINT_16 = new CompactTypeUnsignedInteger(2n ** 16n - 1n, 2);
|
|
40
|
+
/** Descriptor of a Compact `Uint<64>`. */
|
|
41
|
+
export const UINT_64 = new CompactTypeUnsignedInteger(2n ** 64n - 1n, 8);
|
|
42
|
+
/** Descriptor of a Compact `Uint<128>`. */
|
|
43
|
+
export const UINT_128 = new CompactTypeUnsignedInteger(2n ** 128n - 1n, 16);
|
|
44
|
+
/**
|
|
45
|
+
* Descriptor of a Compact `ContractAddress` struct field: a single-field
|
|
46
|
+
* `{ bytes: Bytes<32> }` wrapper, exactly as the compiler generates it.
|
|
47
|
+
*/
|
|
48
|
+
export const CONTRACT_ADDRESS = {
|
|
49
|
+
alignment: () => BYTES_32.alignment(),
|
|
50
|
+
fromValue: (value) => ({ bytes: BYTES_32.fromValue(value) }),
|
|
51
|
+
toValue: (value) => BYTES_32.toValue(value.bytes),
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* Build the runtime descriptor of a Compact struct from its per-field
|
|
55
|
+
* descriptors. Field ORDER is the encoding order and must match the Compact
|
|
56
|
+
* struct declaration order: object literals preserve insertion order for
|
|
57
|
+
* string keys, so pass fields in declaration order.
|
|
58
|
+
*
|
|
59
|
+
* @param fields - One runtime descriptor per struct field, in declaration order.
|
|
60
|
+
* @returns The composed struct descriptor.
|
|
61
|
+
*/
|
|
62
|
+
export function compactStructDescriptor(fields) {
|
|
63
|
+
const entries = Object.entries(fields);
|
|
64
|
+
return {
|
|
65
|
+
alignment: () => entries.flatMap(([, type]) => type.alignment()),
|
|
66
|
+
toValue: (value) => entries.flatMap(([key, type]) => type.toValue(value[key])),
|
|
67
|
+
fromValue: (value) => {
|
|
68
|
+
const result = {};
|
|
69
|
+
for (const [key, type] of entries) {
|
|
70
|
+
result[key] = type.fromValue(value);
|
|
71
|
+
}
|
|
72
|
+
return result;
|
|
73
|
+
},
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Descriptor of Compact's standard-library `Maybe<T>`: the compiler
|
|
78
|
+
* generates it as the struct `{ is_some: Boolean, value: T }`.
|
|
79
|
+
*
|
|
80
|
+
* @param inner - Descriptor of the wrapped type.
|
|
81
|
+
* @returns The Maybe struct descriptor.
|
|
82
|
+
*/
|
|
83
|
+
export function compactMaybeDescriptor(inner) {
|
|
84
|
+
return compactStructDescriptor({
|
|
85
|
+
is_some: CompactTypeBoolean,
|
|
86
|
+
value: inner,
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Decode ONE whole stored value with a descriptor. `fromValue` is a cursor:
|
|
91
|
+
* it consumes atoms from the front of the array it is handed and ignores
|
|
92
|
+
* whatever remains, which is right for descriptors chained mid-struct but
|
|
93
|
+
* wrong for a complete key, cell or payload: called directly it either
|
|
94
|
+
* mutates live state (no copy) or accepts trailing atoms the descriptor
|
|
95
|
+
* never read (copy, no length check). This wrapper owns the copy and rejects
|
|
96
|
+
* leftovers, so a stored shape that has outgrown its descriptor fails loudly
|
|
97
|
+
* instead of decoding a stale prefix.
|
|
98
|
+
*
|
|
99
|
+
* @param type - The descriptor to decode with.
|
|
100
|
+
* @param atoms - The complete stored value. Never mutated.
|
|
101
|
+
* @param what - Error-message subject.
|
|
102
|
+
* @returns The decoded value.
|
|
103
|
+
* @throws {Error} If the descriptor rejects the atoms, or atoms remain after
|
|
104
|
+
* it has consumed its fill.
|
|
105
|
+
*/
|
|
106
|
+
export function decodeExactly(type, atoms, what) {
|
|
107
|
+
const cursor = [...atoms];
|
|
108
|
+
const decoded = type.fromValue(cursor);
|
|
109
|
+
if (cursor.length !== 0) {
|
|
110
|
+
throw new Error(`${what} decode left ${String(cursor.length)} of ${String(atoms.length)} atoms unconsumed`);
|
|
111
|
+
}
|
|
112
|
+
return decoded;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* The declared width of each atom. Signet declares only `Bytes` atoms, so a
|
|
116
|
+
* widthless or nested segment is refused rather than assigned a width.
|
|
117
|
+
*
|
|
118
|
+
* @param cell - The record cell as stored.
|
|
119
|
+
* @param what - Error-message subject.
|
|
120
|
+
* @returns One declared byte width per atom.
|
|
121
|
+
* @throws {Error} If the alignment and value lengths disagree or a segment is
|
|
122
|
+
* not a `Bytes` atom.
|
|
123
|
+
*/
|
|
124
|
+
export function declaredWidths(cell, what) {
|
|
125
|
+
if (cell.alignment.length !== cell.value.length) {
|
|
126
|
+
throw new Error(`${what} declares ${String(cell.alignment.length)} alignment segments for ` +
|
|
127
|
+
`${String(cell.value.length)} atoms`);
|
|
128
|
+
}
|
|
129
|
+
return cell.alignment.map((segment, index) => {
|
|
130
|
+
if (segment.tag !== "atom") {
|
|
131
|
+
throw new Error(`${what} atom ${String(index)} is an alignment option, which no signet type declares`);
|
|
132
|
+
}
|
|
133
|
+
if (segment.value.tag !== "bytes") {
|
|
134
|
+
throw new Error(`${what} atom ${String(index)} is aligned '${segment.value.tag}', which carries no byte width`);
|
|
135
|
+
}
|
|
136
|
+
return segment.value.length;
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
//# sourceMappingURL=compact-descriptors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compact-descriptors.js","sourceRoot":"","sources":["../src/compact-descriptors.ts"],"names":[],"mappings":"AAAA,4EAA4E;AAC5E,yEAAyE;AACzE,6EAA6E;AAC7E,4EAA4E;AAC5E,6EAA6E;AAC7E,4EAA4E;AAC5E,qDAAqD;AACrD,2EAA2E;AAC3E,2EAA2E;AAC3E,4EAA4E;AAC5E,yEAAyE;AACzE,8BAA8B;AAC9B,2EAA2E;AAC3E,2EAA2E;AAC3E,yEAAyE;AACzE,0EAA0E;AAC1E,4CAA4C;AAC5C,sEAAsE;AACtE,wBAAwB;AACxB,EAAE;AACF,0EAA0E;AAC1E,yEAAyE;AACzE,6EAA6E;AAC7E,gCAAgC;AAEhC,OAAO,EAGL,kBAAkB,EAClB,gBAAgB,EAChB,0BAA0B,GAC3B,MAAM,iCAAiC,CAAC;AAEzC,0EAA0E;AAC1E,kBAAkB;AAElB,0CAA0C;AAC1C,MAAM,CAAC,MAAM,OAAO,GAAG,IAAI,gBAAgB,CAAC,CAAC,CAAC,CAAC;AAC/C,2CAA2C;AAC3C,MAAM,CAAC,MAAM,QAAQ,GAAG,IAAI,gBAAgB,CAAC,EAAE,CAAC,CAAC;AACjD,2CAA2C;A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AAkB,EAAE,IAAY;IAC7D,IAAI,IAAI,CAAC,SAAS,CAAC,MAAM,KAAK,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC;QAChD,MAAM,IAAI,KAAK,CACb,GAAG,IAAI,aAAa,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,0BAA0B;YACzE,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,QAAQ,CACvC,CAAC;IACJ,CAAC;IACD,OAAO,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,KAAK,EAAE,EAAE;QAC3C,IAAI,OAAO,CAAC,GAAG,KAAK,MAAM,EAAE,CAAC;YAC3B,MAAM,IAAI,KAAK,CACb,GAAG,IAAI,SAAS,MAAM,CAAC,KAAK,CAAC,wDAAwD,CACtF,CAAC;QACJ,CAAC;QACD,IAAI,OAAO,CAAC,KAAK,CAAC,GAAG,KAAK,OAAO,EAAE,CAAC;YAClC,MAAM,IAAI,KAAK,CACb,GAAG,IAAI,SAAS,MAAM,CAAC,KAAK,CAAC,gBAAgB,OAAO,CAAC,KAAK,CAAC,GAAG,gCAAgC,CAC/F,CAAC;QACJ,CAAC;QACD,OAAO,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC;IAC9B,CAAC,CAAC,CAAC;AACL,CAAC"}
|
package/dist/constants.d.ts
CHANGED
|
@@ -7,41 +7,25 @@ export declare const SELECTOR_BYTES = 4;
|
|
|
7
7
|
/**
|
|
8
8
|
* The complete serialised output the MPC attests for a FAILED remote
|
|
9
9
|
* execution (reverted or replaced transaction): the 4-byte error marker
|
|
10
|
-
* `0xdeadbeef` followed by one `0x01` byte
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
* The exact-equality check ({@link isMpcFailureOutput}) is unambiguous for
|
|
17
|
-
* every respond schema whose packed width differs from 5 bytes. A schema
|
|
18
|
-
* whose packed width is exactly 5 could in principle produce a legitimate
|
|
19
|
-
* output equal to this sentinel, and such clients must route settlement by
|
|
20
|
-
* digest-candidate matching (recompute both the real-output candidate and
|
|
21
|
-
* the failure candidate, and see which digest the MPC attested), never by
|
|
22
|
-
* inspecting output bytes.
|
|
10
|
+
* `0xdeadbeef` followed by one `0x01` byte, mirroring the canonical MPC's
|
|
11
|
+
* failure payload (sig-net/mpc, node/src/respond_bidirectional.rs). A
|
|
12
|
+
* respond schema whose packed width is exactly 5 bytes could produce a
|
|
13
|
+
* legitimate output equal to this sentinel: such clients must route
|
|
14
|
+
* settlement by digest-candidate matching, never by inspecting output
|
|
15
|
+
* bytes. See {@link isMpcFailureOutput}.
|
|
23
16
|
*/
|
|
24
17
|
export declare const MPC_FAILURE_OUTPUT: Uint8Array<ArrayBuffer>;
|
|
25
18
|
/**
|
|
26
19
|
* Whether an attested serialised output IS the MPC's fixed failure payload:
|
|
27
|
-
* exact byte equality with the 5-byte {@link MPC_FAILURE_OUTPUT}
|
|
28
|
-
* must be exactly 5 and every byte must match). A prefix check would be
|
|
29
|
-
* unsafe, as a legitimate packed output can begin with the same bytes.
|
|
30
|
-
*
|
|
31
|
-
* Unambiguous for every respond schema whose packed width differs from 5
|
|
32
|
-
* bytes. A schema whose packed width is exactly 5 could in principle produce
|
|
33
|
-
* a legitimate output equal to the sentinel: such clients must route
|
|
34
|
-
* settlement by digest-candidate matching instead of inspecting output
|
|
35
|
-
* bytes (see {@link MPC_FAILURE_OUTPUT}).
|
|
20
|
+
* exact byte equality with the 5-byte {@link MPC_FAILURE_OUTPUT}.
|
|
36
21
|
*
|
|
37
22
|
* @param serializedOutput - The attested serialised output.
|
|
38
23
|
* @returns `true` when the output equals the MPC failure payload exactly.
|
|
39
24
|
*/
|
|
40
25
|
export declare function isMpcFailureOutput(serializedOutput: Uint8Array): boolean;
|
|
41
26
|
/**
|
|
42
|
-
* Default MPC key version (`keyVersion` field value).
|
|
43
|
-
*
|
|
44
|
-
* `constructSignBidirectionalEvent`) requires `keyVersion >= 1`.
|
|
27
|
+
* Default MPC key version (`keyVersion` field value). The canonical MPC
|
|
28
|
+
* (and `constructSignBidirectionalEvent`) requires `keyVersion >= 1`.
|
|
45
29
|
*/
|
|
46
30
|
export declare const SIGNET_DEFAULT_KEY_VERSION = 1n;
|
|
47
31
|
/**
|
|
@@ -52,15 +36,12 @@ export declare const SIGNET_DEFAULT_KEY_VERSION = 1n;
|
|
|
52
36
|
* @param text - The ASCII text to encode.
|
|
53
37
|
* @param length - The fixed field width in bytes.
|
|
54
38
|
* @returns `text`'s bytes followed by zero padding to exactly `length`.
|
|
55
|
-
* @throws If the encoded text does not fit in `length` bytes.
|
|
39
|
+
* @throws {Error} If the encoded text does not fit in `length` bytes.
|
|
56
40
|
*/
|
|
57
41
|
export declare function asciiPadded(text: string, length: number): Uint8Array;
|
|
58
42
|
/**
|
|
59
43
|
* A named Midnight network: the single source of the network names shared
|
|
60
|
-
* across the `@sig-net/midnight*` packages.
|
|
61
|
-
* as a bare `string` with no companion enum, so the names live here, and
|
|
62
|
-
* `@sig-net/midnight-contract-deploy`'s network-id plumbing widens this
|
|
63
|
-
* enum back to the SDK's string type for its deploy config.
|
|
44
|
+
* across the `@sig-net/midnight*` packages.
|
|
64
45
|
*/
|
|
65
46
|
export declare enum MidnightNetwork {
|
|
66
47
|
/** Local standalone stack (Docker node, indexer and proof server on localhost). */
|
|
@@ -78,35 +59,29 @@ export declare enum MidnightNetwork {
|
|
|
78
59
|
* A public, long-lived Midnight network: every named network except the
|
|
79
60
|
* local standalone stack. Only these have fixed protocol counterparty
|
|
80
61
|
* values published in this package (see {@link getMpcRootPublicKey} and
|
|
81
|
-
* {@link getSignetContractAddress})
|
|
82
|
-
* per deployment instead.
|
|
62
|
+
* {@link getSignetContractAddress}).
|
|
83
63
|
*/
|
|
84
64
|
export type DeployedNetwork = Exclude<MidnightNetwork, MidnightNetwork.Undeployed>;
|
|
85
65
|
/**
|
|
86
66
|
* The MPC root public key of a deployed Midnight network, as hex: the
|
|
87
67
|
* `mpcRootPublicKey` every client key derivation starts from (see
|
|
88
|
-
* `deriveEvmAddress`).
|
|
89
|
-
*
|
|
90
|
-
* `MPC_ROOT_KEY` per stack (the integration-test setup prints it and
|
|
91
|
-
* appends it to the repo-root `.env`).
|
|
68
|
+
* `deriveEvmAddress`). A local standalone stack has no fixed key: its setup
|
|
69
|
+
* generates a fresh `MPC_ROOT_KEY` per stack.
|
|
92
70
|
*
|
|
93
71
|
* @param networkId - The deployed network to look up.
|
|
94
72
|
* @returns The network's MPC root public key.
|
|
95
|
-
* @throws Error
|
|
73
|
+
* @throws {Error} When the network's key is not yet published in this package.
|
|
96
74
|
*/
|
|
97
75
|
export declare function getMpcRootPublicKey(networkId: DeployedNetwork): string;
|
|
98
76
|
/**
|
|
99
77
|
* The address of the central signet singleton contract on a deployed
|
|
100
78
|
* Midnight network: the `signetContractAddress` a
|
|
101
|
-
* `SignetRequestResponseReader` polls.
|
|
102
|
-
*
|
|
103
|
-
* stack deploys its own singleton (the integration-test setup prints the
|
|
104
|
-
* address as `MIDNIGHT_SIGNET_CONTRACT_ADDRESS` and appends it to the
|
|
105
|
-
* repo-root `.env`).
|
|
79
|
+
* `SignetRequestResponseReader` polls. A local standalone stack has no
|
|
80
|
+
* fixed address: each stack deploys its own singleton.
|
|
106
81
|
*
|
|
107
82
|
* @param networkId - The deployed network to look up.
|
|
108
83
|
* @returns The network's signet contract address.
|
|
109
|
-
* @throws Error
|
|
84
|
+
* @throws {Error} When the singleton's address is not yet published in this
|
|
110
85
|
* package.
|
|
111
86
|
*/
|
|
112
87
|
export declare function getSignetContractAddress(networkId: DeployedNetwork): string;
|
package/dist/constants.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AASA,+DAA+D;AAC/D,eAAO,MAAM,cAAc,KAAK,CAAC;AAEjC,8DAA8D;AAC9D,eAAO,MAAM,gBAAgB,KAAK,CAAC;AAEnC,wFAAwF;AACxF,eAAO,MAAM,cAAc,IAAI,CAAC;AAEhC;;;;;;;;;GASG;AACH,eAAO,MAAM,kBAAkB,yBAAiD,CAAC;AAEjF;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,gBAAgB,EAAE,UAAU,GAAG,OAAO,CAKxE;AAED;;;GAGG;AACH,eAAO,MAAM,0BAA0B,KAAK,CAAC;AAE7C;;;;;;;;;GASG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,UAAU,CAUpE;AAED;;;GAGG;AACH,oBAAY,eAAe;IACzB,mFAAmF;IACnF,UAAU,eAAe;IACzB,2CAA2C;IAC3C,QAAQ,aAAa;IACrB,iFAAiF;IACjF,OAAO,YAAY;IACnB,+EAA+E;IAC/E,OAAO,YAAY;IACnB,6CAA6C;IAC7C,OAAO,YAAY;CACpB;AAED;;;;;GAKG;AACH,MAAM,MAAM,eAAe,GAAG,OAAO,CAAC,eAAe,EAAE,eAAe,CAAC,UAAU,CAAC,CAAC;AAYnF;;;;;;;;;GASG;AACH,wBAAgB,mBAAmB,CAAC,SAAS,EAAE,eAAe,GAAG,MAAM,CAMtE;AAYD;;;;;;;;;;GAUG;AACH,wBAAgB,wBAAwB,CAAC,SAAS,EAAE,eAAe,GAAG,MAAM,CAM3E"}
|