@cardanowall/sdk-ts 0.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/LICENSE +202 -0
- package/README.md +207 -0
- package/dist/client/index.cjs +2695 -0
- package/dist/client/index.cjs.map +1 -0
- package/dist/client/index.d.cts +397 -0
- package/dist/client/index.d.ts +397 -0
- package/dist/client/index.js +2641 -0
- package/dist/client/index.js.map +1 -0
- package/dist/conformance/cli.cjs +4901 -0
- package/dist/conformance/cli.cjs.map +1 -0
- package/dist/conformance/cli.d.cts +18 -0
- package/dist/conformance/cli.d.ts +18 -0
- package/dist/conformance/cli.js +4878 -0
- package/dist/conformance/cli.js.map +1 -0
- package/dist/fetch/index.cjs +335 -0
- package/dist/fetch/index.cjs.map +1 -0
- package/dist/fetch/index.d.cts +13 -0
- package/dist/fetch/index.d.ts +13 -0
- package/dist/fetch/index.js +323 -0
- package/dist/fetch/index.js.map +1 -0
- package/dist/fetch-outbound-BT5-NiYN.d.cts +76 -0
- package/dist/fetch-outbound-BT5-NiYN.d.ts +76 -0
- package/dist/hash/index.cjs +25 -0
- package/dist/hash/index.cjs.map +1 -0
- package/dist/hash/index.d.cts +1 -0
- package/dist/hash/index.d.ts +1 -0
- package/dist/hash/index.js +21 -0
- package/dist/hash/index.js.map +1 -0
- package/dist/identity/index.cjs +1388 -0
- package/dist/identity/index.cjs.map +1 -0
- package/dist/identity/index.d.cts +27 -0
- package/dist/identity/index.d.ts +27 -0
- package/dist/identity/index.js +1362 -0
- package/dist/identity/index.js.map +1 -0
- package/dist/ids/index.cjs +146 -0
- package/dist/ids/index.cjs.map +1 -0
- package/dist/ids/index.d.cts +55 -0
- package/dist/ids/index.d.ts +55 -0
- package/dist/ids/index.js +135 -0
- package/dist/ids/index.js.map +1 -0
- package/dist/index-BhnlWJAY.d.cts +10 -0
- package/dist/index-BhnlWJAY.d.ts +10 -0
- package/dist/index-Cg1QqVmA.d.cts +19 -0
- package/dist/index-Cg1QqVmA.d.ts +19 -0
- package/dist/index.cjs +7127 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +21 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.js +7004 -0
- package/dist/index.js.map +1 -0
- package/dist/merkle/index.cjs +396 -0
- package/dist/merkle/index.cjs.map +1 -0
- package/dist/merkle/index.d.cts +2 -0
- package/dist/merkle/index.d.ts +2 -0
- package/dist/merkle/index.js +387 -0
- package/dist/merkle/index.js.map +1 -0
- package/dist/types-B8Q3gW54.d.ts +123 -0
- package/dist/types-BQMtbRCb.d.cts +321 -0
- package/dist/types-BQMtbRCb.d.ts +321 -0
- package/dist/types-CLXdbjqr.d.cts +123 -0
- package/dist/verifier/index.cjs +4901 -0
- package/dist/verifier/index.cjs.map +1 -0
- package/dist/verifier/index.d.cts +176 -0
- package/dist/verifier/index.d.ts +176 -0
- package/dist/verifier/index.js +4848 -0
- package/dist/verifier/index.js.map +1 -0
- package/package.json +108 -0
|
@@ -0,0 +1,387 @@
|
|
|
1
|
+
import { sha256 } from '@noble/hashes/sha2.js';
|
|
2
|
+
import '@noble/hashes/blake2.js';
|
|
3
|
+
import 'hash-wasm';
|
|
4
|
+
import { encode, decode, cdeDecodeOptions } from 'cbor2';
|
|
5
|
+
import { sortCoreDeterministic } from 'cbor2/sorts';
|
|
6
|
+
|
|
7
|
+
// ../crypto-core/dist/hash.js
|
|
8
|
+
function compareCt(a, b) {
|
|
9
|
+
if (a.length !== b.length) return false;
|
|
10
|
+
let diff = 0;
|
|
11
|
+
for (let i = 0; i < a.length; i++) diff |= a[i] ^ b[i];
|
|
12
|
+
return diff === 0;
|
|
13
|
+
}
|
|
14
|
+
var MERKLE_ALG_ID = "rfc9162-sha256";
|
|
15
|
+
var LEAF_PREFIX = 0;
|
|
16
|
+
var NODE_PREFIX = 1;
|
|
17
|
+
var DIGEST_LENGTH = 32;
|
|
18
|
+
function validateLeaves(leaves, fnName) {
|
|
19
|
+
if (leaves.length === 0) {
|
|
20
|
+
throw new Error(`${fnName}: empty leaf list (n == 0 is forbidden by RFC 9162 \xA72.1.1)`);
|
|
21
|
+
}
|
|
22
|
+
for (let i = 0; i < leaves.length; i++) {
|
|
23
|
+
const leaf = leaves[i];
|
|
24
|
+
if (!(leaf instanceof Uint8Array) || leaf.length !== DIGEST_LENGTH) {
|
|
25
|
+
throw new Error(
|
|
26
|
+
`${fnName}: leaf[${i}] must be a Uint8Array(${DIGEST_LENGTH}); got length ${leaf instanceof Uint8Array ? leaf.length : "non-Uint8Array"}`
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
function merkleSha2256Root(leaves) {
|
|
32
|
+
validateLeaves(leaves, "merkleSha2256Root");
|
|
33
|
+
return mthRecursive(leaves, 0, leaves.length);
|
|
34
|
+
}
|
|
35
|
+
function merkleSha2256InclusionProof(leaves, index) {
|
|
36
|
+
validateLeaves(leaves, "merkleSha2256InclusionProof");
|
|
37
|
+
if (!Number.isInteger(index) || index < 0 || index >= leaves.length) {
|
|
38
|
+
throw new Error(
|
|
39
|
+
`merkleSha2256InclusionProof: index ${index} out of range [0, ${leaves.length})`
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
return auditPath(leaves, index, 0, leaves.length);
|
|
43
|
+
}
|
|
44
|
+
function merkleSha2256VerifyInclusion(leaf, index, treeSize, proof, root) {
|
|
45
|
+
if (!(leaf instanceof Uint8Array) || leaf.length !== DIGEST_LENGTH) return false;
|
|
46
|
+
if (!(root instanceof Uint8Array) || root.length !== DIGEST_LENGTH) return false;
|
|
47
|
+
if (!Number.isInteger(index) || !Number.isInteger(treeSize) || treeSize < 1 || index < 0 || index >= treeSize) {
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
for (let i = 0; i < proof.length; i++) {
|
|
51
|
+
const sibling = proof[i];
|
|
52
|
+
if (!(sibling instanceof Uint8Array) || sibling.length !== DIGEST_LENGTH) {
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
if (treeSize === 1) {
|
|
57
|
+
if (proof.length !== 0 || index !== 0) return false;
|
|
58
|
+
return compareCt(hashLeaf(leaf), root);
|
|
59
|
+
}
|
|
60
|
+
let h = hashLeaf(leaf);
|
|
61
|
+
let sn = index;
|
|
62
|
+
let fn = treeSize - 1;
|
|
63
|
+
for (let i = 0; i < proof.length; i++) {
|
|
64
|
+
if (fn === 0) return false;
|
|
65
|
+
const sibling = proof[i];
|
|
66
|
+
if ((sn & 1) === 1 || sn === fn) {
|
|
67
|
+
h = hashNode(sibling, h);
|
|
68
|
+
while ((sn & 1) === 0 && sn !== 0) {
|
|
69
|
+
sn >>>= 1;
|
|
70
|
+
fn >>>= 1;
|
|
71
|
+
}
|
|
72
|
+
} else {
|
|
73
|
+
h = hashNode(h, sibling);
|
|
74
|
+
}
|
|
75
|
+
sn >>>= 1;
|
|
76
|
+
fn >>>= 1;
|
|
77
|
+
}
|
|
78
|
+
if (fn !== 0) return false;
|
|
79
|
+
return compareCt(h, root);
|
|
80
|
+
}
|
|
81
|
+
function largestPow2Lt(n) {
|
|
82
|
+
let k = 1;
|
|
83
|
+
while (k * 2 < n) k *= 2;
|
|
84
|
+
return k;
|
|
85
|
+
}
|
|
86
|
+
function hashLeaf(d) {
|
|
87
|
+
const buf = new Uint8Array(1 + d.length);
|
|
88
|
+
buf[0] = LEAF_PREFIX;
|
|
89
|
+
buf.set(d, 1);
|
|
90
|
+
return sha256(buf);
|
|
91
|
+
}
|
|
92
|
+
function hashNode(left, right) {
|
|
93
|
+
const buf = new Uint8Array(1 + left.length + right.length);
|
|
94
|
+
buf[0] = NODE_PREFIX;
|
|
95
|
+
buf.set(left, 1);
|
|
96
|
+
buf.set(right, 1 + left.length);
|
|
97
|
+
return sha256(buf);
|
|
98
|
+
}
|
|
99
|
+
function mthRecursive(leaves, start, end) {
|
|
100
|
+
const n = end - start;
|
|
101
|
+
if (n === 1) {
|
|
102
|
+
return hashLeaf(leaves[start]);
|
|
103
|
+
}
|
|
104
|
+
const k = largestPow2Lt(n);
|
|
105
|
+
const left = mthRecursive(leaves, start, start + k);
|
|
106
|
+
const right = mthRecursive(leaves, start + k, end);
|
|
107
|
+
return hashNode(left, right);
|
|
108
|
+
}
|
|
109
|
+
function auditPath(leaves, i, start, end) {
|
|
110
|
+
const n = end - start;
|
|
111
|
+
if (n === 1) return [];
|
|
112
|
+
const k = largestPow2Lt(n);
|
|
113
|
+
if (i < k) {
|
|
114
|
+
const subPath2 = auditPath(leaves, i, start, start + k);
|
|
115
|
+
subPath2.push(mthRecursive(leaves, start + k, end));
|
|
116
|
+
return subPath2;
|
|
117
|
+
}
|
|
118
|
+
const subPath = auditPath(leaves, i - k, start + k, end);
|
|
119
|
+
subPath.push(mthRecursive(leaves, start, start + k));
|
|
120
|
+
return subPath;
|
|
121
|
+
}
|
|
122
|
+
var CanonicalCborError = class extends Error {
|
|
123
|
+
code;
|
|
124
|
+
constructor(code, message, options) {
|
|
125
|
+
super(message, options);
|
|
126
|
+
this.name = "CanonicalCborError";
|
|
127
|
+
this.code = code;
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
function encodeCanonicalCbor(value) {
|
|
131
|
+
return encode(value, {
|
|
132
|
+
cde: true,
|
|
133
|
+
collapseBigInts: true,
|
|
134
|
+
rejectDuplicateKeys: true,
|
|
135
|
+
sortKeys: sortCoreDeterministic
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
function decodeCanonicalCbor(bytes) {
|
|
139
|
+
try {
|
|
140
|
+
return decode(bytes, {
|
|
141
|
+
...cdeDecodeOptions,
|
|
142
|
+
rejectStreaming: true,
|
|
143
|
+
rejectDuplicateKeys: true,
|
|
144
|
+
// A CIP-309 record carries integers, byte/text strings, arrays, maps and
|
|
145
|
+
// `null` — and nothing else. Without these rejections the major-type-7
|
|
146
|
+
// surface leaks into the decoder: a float16/32/64 that happens to hold an
|
|
147
|
+
// integral value (e.g. 1.0) silently decodes to the integer 1 and passes
|
|
148
|
+
// a `z.literal(1)` / Number.isInteger schema check, so two byte strings
|
|
149
|
+
// that are NOT byte-identical canonicalise to the same record. That
|
|
150
|
+
// breaks the cross-implementation parity invariant (the Python twin
|
|
151
|
+
// already rejects non-integer `v` / `enc.scheme` outright). Reject the
|
|
152
|
+
// whole non-record surface — floats, negative zero, undefined, and
|
|
153
|
+
// non-{true,false,null} simple values — so any such input surfaces as
|
|
154
|
+
// MALFORMED_CBOR via mapDecodeError rather than decoding to a look-alike.
|
|
155
|
+
rejectFloats: true,
|
|
156
|
+
rejectNegativeZero: true,
|
|
157
|
+
rejectUndefined: true,
|
|
158
|
+
rejectSimple: true
|
|
159
|
+
});
|
|
160
|
+
} catch (cause) {
|
|
161
|
+
throw mapDecodeError(cause);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
function mapDecodeError(cause) {
|
|
165
|
+
const message = cause instanceof Error ? cause.message : String(cause);
|
|
166
|
+
const lower = message.toLowerCase();
|
|
167
|
+
const isIndefinite = lower.includes("streaming") || lower.includes("indefinite");
|
|
168
|
+
const detail = isIndefinite ? `indefinite-length items are not permitted in canonical CBOR: ${message}` : message;
|
|
169
|
+
return new CanonicalCborError("MALFORMED_CBOR", `cbor decode failed: ${detail}`, { cause });
|
|
170
|
+
}
|
|
171
|
+
function compareCt2(a, b) {
|
|
172
|
+
if (a.length !== b.length) return false;
|
|
173
|
+
let diff = 0;
|
|
174
|
+
for (let i = 0; i < a.length; i++) diff |= a[i] ^ b[i];
|
|
175
|
+
return diff === 0;
|
|
176
|
+
}
|
|
177
|
+
var LEAF_PREFIX2 = 0;
|
|
178
|
+
var NODE_PREFIX2 = 1;
|
|
179
|
+
var DIGEST_LENGTH2 = 32;
|
|
180
|
+
function validateLeaves2(leaves, fnName) {
|
|
181
|
+
if (leaves.length === 0) {
|
|
182
|
+
throw new Error(`${fnName}: empty leaf list (n == 0 is forbidden by RFC 9162 \xA72.1.1)`);
|
|
183
|
+
}
|
|
184
|
+
for (let i = 0; i < leaves.length; i++) {
|
|
185
|
+
const leaf = leaves[i];
|
|
186
|
+
if (!(leaf instanceof Uint8Array) || leaf.length !== DIGEST_LENGTH2) {
|
|
187
|
+
throw new Error(
|
|
188
|
+
`${fnName}: leaf[${i}] must be a Uint8Array(${DIGEST_LENGTH2}); got length ${leaf instanceof Uint8Array ? leaf.length : "non-Uint8Array"}`
|
|
189
|
+
);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
function merkleSha2256Root2(leaves) {
|
|
194
|
+
validateLeaves2(leaves, "merkleSha2256Root");
|
|
195
|
+
return mthRecursive2(leaves, 0, leaves.length);
|
|
196
|
+
}
|
|
197
|
+
function largestPow2Lt2(n) {
|
|
198
|
+
let k = 1;
|
|
199
|
+
while (k * 2 < n) k *= 2;
|
|
200
|
+
return k;
|
|
201
|
+
}
|
|
202
|
+
function hashLeaf2(d) {
|
|
203
|
+
const buf = new Uint8Array(1 + d.length);
|
|
204
|
+
buf[0] = LEAF_PREFIX2;
|
|
205
|
+
buf.set(d, 1);
|
|
206
|
+
return sha256(buf);
|
|
207
|
+
}
|
|
208
|
+
function hashNode2(left, right) {
|
|
209
|
+
const buf = new Uint8Array(1 + left.length + right.length);
|
|
210
|
+
buf[0] = NODE_PREFIX2;
|
|
211
|
+
buf.set(left, 1);
|
|
212
|
+
buf.set(right, 1 + left.length);
|
|
213
|
+
return sha256(buf);
|
|
214
|
+
}
|
|
215
|
+
function mthRecursive2(leaves, start, end) {
|
|
216
|
+
const n = end - start;
|
|
217
|
+
if (n === 1) {
|
|
218
|
+
return hashLeaf2(leaves[start]);
|
|
219
|
+
}
|
|
220
|
+
const k = largestPow2Lt2(n);
|
|
221
|
+
const left = mthRecursive2(leaves, start, start + k);
|
|
222
|
+
const right = mthRecursive2(leaves, start + k, end);
|
|
223
|
+
return hashNode2(left, right);
|
|
224
|
+
}
|
|
225
|
+
var LEAVES_LIST_FORMAT_V1 = "cardano-poe-merkle-leaves-v1";
|
|
226
|
+
var TREE_ALG_RFC9162 = "rfc9162-sha256";
|
|
227
|
+
var DIGEST_LENGTH22 = 32;
|
|
228
|
+
var REGISTERED_FORMATS = /* @__PURE__ */ new Set([LEAVES_LIST_FORMAT_V1]);
|
|
229
|
+
var MerkleLeavesListError = class extends Error {
|
|
230
|
+
code;
|
|
231
|
+
constructor(code, message) {
|
|
232
|
+
super(message ? `${code}: ${message}` : code);
|
|
233
|
+
this.code = code;
|
|
234
|
+
this.name = "MerkleLeavesListError";
|
|
235
|
+
}
|
|
236
|
+
};
|
|
237
|
+
function encodeLeavesList(args) {
|
|
238
|
+
if (!(args.root instanceof Uint8Array) || args.root.length !== DIGEST_LENGTH22) {
|
|
239
|
+
throw new MerkleLeavesListError(
|
|
240
|
+
"SCHEMA_MERKLE_LEAVES_MALFORMED",
|
|
241
|
+
`root must be a Uint8Array(${DIGEST_LENGTH22})`
|
|
242
|
+
);
|
|
243
|
+
}
|
|
244
|
+
if (args.leaves.length < 1) {
|
|
245
|
+
throw new MerkleLeavesListError(
|
|
246
|
+
"SCHEMA_MERKLE_LEAVES_MALFORMED",
|
|
247
|
+
"leaves array must be non-empty"
|
|
248
|
+
);
|
|
249
|
+
}
|
|
250
|
+
const leavesCopy = [];
|
|
251
|
+
for (let i = 0; i < args.leaves.length; i++) {
|
|
252
|
+
const leaf = args.leaves[i];
|
|
253
|
+
if (!(leaf instanceof Uint8Array) || leaf.length !== DIGEST_LENGTH22) {
|
|
254
|
+
throw new MerkleLeavesListError(
|
|
255
|
+
"SCHEMA_MERKLE_LEAVES_MALFORMED",
|
|
256
|
+
`leaves[${i}] must be a Uint8Array(${DIGEST_LENGTH22})`
|
|
257
|
+
);
|
|
258
|
+
}
|
|
259
|
+
leavesCopy.push(leaf);
|
|
260
|
+
}
|
|
261
|
+
if (args.leafAlg !== void 0 && typeof args.leafAlg !== "string") {
|
|
262
|
+
throw new MerkleLeavesListError(
|
|
263
|
+
"SCHEMA_MERKLE_LEAVES_MALFORMED",
|
|
264
|
+
"leaf_alg must be a string when present"
|
|
265
|
+
);
|
|
266
|
+
}
|
|
267
|
+
const map = {
|
|
268
|
+
format: LEAVES_LIST_FORMAT_V1,
|
|
269
|
+
tree_alg: TREE_ALG_RFC9162,
|
|
270
|
+
root: args.root,
|
|
271
|
+
leaves: leavesCopy,
|
|
272
|
+
leaf_count: leavesCopy.length
|
|
273
|
+
};
|
|
274
|
+
if (args.leafAlg !== void 0) {
|
|
275
|
+
map["leaf_alg"] = args.leafAlg;
|
|
276
|
+
}
|
|
277
|
+
return encodeCanonicalCbor(map);
|
|
278
|
+
}
|
|
279
|
+
function decodeLeavesList(bytes) {
|
|
280
|
+
const decoded = decodeCanonicalCbor(bytes);
|
|
281
|
+
if (typeof decoded !== "object" || decoded === null || Array.isArray(decoded)) {
|
|
282
|
+
throw new MerkleLeavesListError(
|
|
283
|
+
"SCHEMA_MERKLE_LEAVES_MALFORMED",
|
|
284
|
+
"leaves-list MUST be a CBOR map"
|
|
285
|
+
);
|
|
286
|
+
}
|
|
287
|
+
const m = decoded;
|
|
288
|
+
const format = m["format"];
|
|
289
|
+
if (typeof format !== "string") {
|
|
290
|
+
throw new MerkleLeavesListError(
|
|
291
|
+
"SCHEMA_MERKLE_LEAVES_MALFORMED",
|
|
292
|
+
"format must be a text string"
|
|
293
|
+
);
|
|
294
|
+
}
|
|
295
|
+
if (!REGISTERED_FORMATS.has(format)) {
|
|
296
|
+
throw new MerkleLeavesListError(
|
|
297
|
+
"SCHEMA_MERKLE_LEAVES_FORMAT_UNSUPPORTED",
|
|
298
|
+
`format '${format}' is not in the registered set`
|
|
299
|
+
);
|
|
300
|
+
}
|
|
301
|
+
const treeAlg = m["tree_alg"];
|
|
302
|
+
if (treeAlg !== TREE_ALG_RFC9162) {
|
|
303
|
+
throw new MerkleLeavesListError(
|
|
304
|
+
"SCHEMA_MERKLE_LEAVES_MALFORMED",
|
|
305
|
+
`tree_alg '${String(treeAlg)}' is not '${TREE_ALG_RFC9162}'`
|
|
306
|
+
);
|
|
307
|
+
}
|
|
308
|
+
const root = m["root"];
|
|
309
|
+
if (!(root instanceof Uint8Array) || root.length !== DIGEST_LENGTH22) {
|
|
310
|
+
throw new MerkleLeavesListError(
|
|
311
|
+
"SCHEMA_MERKLE_LEAVES_MALFORMED",
|
|
312
|
+
`root must be a ${DIGEST_LENGTH22}-byte byte string`
|
|
313
|
+
);
|
|
314
|
+
}
|
|
315
|
+
const leavesRaw = m["leaves"];
|
|
316
|
+
if (!Array.isArray(leavesRaw) || leavesRaw.length < 1) {
|
|
317
|
+
throw new MerkleLeavesListError(
|
|
318
|
+
"SCHEMA_MERKLE_LEAVES_MALFORMED",
|
|
319
|
+
"leaves must be a non-empty array"
|
|
320
|
+
);
|
|
321
|
+
}
|
|
322
|
+
const leaves = [];
|
|
323
|
+
for (let i = 0; i < leavesRaw.length; i++) {
|
|
324
|
+
const leaf = leavesRaw[i];
|
|
325
|
+
if (!(leaf instanceof Uint8Array) || leaf.length !== DIGEST_LENGTH22) {
|
|
326
|
+
throw new MerkleLeavesListError(
|
|
327
|
+
"SCHEMA_MERKLE_LEAVES_MALFORMED",
|
|
328
|
+
`leaves[${i}] must be a ${DIGEST_LENGTH22}-byte byte string`
|
|
329
|
+
);
|
|
330
|
+
}
|
|
331
|
+
leaves.push(leaf);
|
|
332
|
+
}
|
|
333
|
+
const leafCountRaw = m["leaf_count"];
|
|
334
|
+
let leafCount;
|
|
335
|
+
if (typeof leafCountRaw === "number" && Number.isInteger(leafCountRaw) && leafCountRaw >= 0) {
|
|
336
|
+
leafCount = leafCountRaw;
|
|
337
|
+
} else if (typeof leafCountRaw === "bigint" && leafCountRaw >= 0n) {
|
|
338
|
+
if (leafCountRaw > BigInt(Number.MAX_SAFE_INTEGER)) {
|
|
339
|
+
throw new MerkleLeavesListError(
|
|
340
|
+
"SCHEMA_MERKLE_LEAVES_MALFORMED",
|
|
341
|
+
"leaf_count exceeds Number.MAX_SAFE_INTEGER"
|
|
342
|
+
);
|
|
343
|
+
}
|
|
344
|
+
leafCount = Number(leafCountRaw);
|
|
345
|
+
} else {
|
|
346
|
+
throw new MerkleLeavesListError(
|
|
347
|
+
"SCHEMA_MERKLE_LEAVES_MALFORMED",
|
|
348
|
+
"leaf_count must be a non-negative CBOR uint"
|
|
349
|
+
);
|
|
350
|
+
}
|
|
351
|
+
if (leaves.length !== leafCount) {
|
|
352
|
+
throw new MerkleLeavesListError(
|
|
353
|
+
"SCHEMA_MERKLE_LEAF_COUNT_MISMATCH",
|
|
354
|
+
`leaves.length (${leaves.length}) != leaf_count (${leafCount})`
|
|
355
|
+
);
|
|
356
|
+
}
|
|
357
|
+
let leafAlg;
|
|
358
|
+
if (m["leaf_alg"] !== void 0) {
|
|
359
|
+
if (typeof m["leaf_alg"] !== "string") {
|
|
360
|
+
throw new MerkleLeavesListError(
|
|
361
|
+
"SCHEMA_MERKLE_LEAVES_MALFORMED",
|
|
362
|
+
"leaf_alg must be a text string when present"
|
|
363
|
+
);
|
|
364
|
+
}
|
|
365
|
+
leafAlg = m["leaf_alg"];
|
|
366
|
+
}
|
|
367
|
+
const recomputed = merkleSha2256Root2(leaves);
|
|
368
|
+
if (!compareCt2(recomputed, root)) {
|
|
369
|
+
throw new MerkleLeavesListError(
|
|
370
|
+
"MERKLE_ROOT_MISMATCH",
|
|
371
|
+
"leaves recompute does not match declared root"
|
|
372
|
+
);
|
|
373
|
+
}
|
|
374
|
+
const out = {
|
|
375
|
+
format: LEAVES_LIST_FORMAT_V1,
|
|
376
|
+
treeAlg: TREE_ALG_RFC9162,
|
|
377
|
+
root,
|
|
378
|
+
leaves,
|
|
379
|
+
leafCount,
|
|
380
|
+
...leafAlg !== void 0 ? { leafAlg } : {}
|
|
381
|
+
};
|
|
382
|
+
return out;
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
export { LEAVES_LIST_FORMAT_V1, MERKLE_ALG_ID, MerkleLeavesListError, decodeLeavesList, encodeLeavesList, merkleSha2256InclusionProof, merkleSha2256Root, merkleSha2256VerifyInclusion };
|
|
386
|
+
//# sourceMappingURL=index.js.map
|
|
387
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../crypto-core/src/util/compare-ct.ts","../../../crypto-core/src/hash/merkle-sha2-256.ts","../../../crypto-core/src/cbor/errors.ts","../../../crypto-core/src/cbor/canonical.ts","../../../crypto-core/src/merkle/leaves-list.ts"],"names":["sha256","subPath","compareCt","LEAF_PREFIX","NODE_PREFIX","DIGEST_LENGTH","validateLeaves","merkleSha2256Root","mthRecursive","largestPow2Lt","hashLeaf","hashNode"],"mappings":";;;;;;;AAKO,SAAS,SAAA,CAAU,GAAe,CAAA,EAAwB;AAC/D,EAAA,IAAI,CAAA,CAAE,MAAA,KAAW,CAAA,CAAE,MAAA,EAAQ,OAAO,KAAA;AAClC,EAAA,IAAI,IAAA,GAAO,CAAA;AAIX,EAAA,KAAA,IAAS,CAAA,GAAI,CAAA,EAAG,CAAA,GAAI,CAAA,CAAE,MAAA,EAAQ,CAAA,EAAA,EAAK,IAAA,IAAS,CAAA,CAAE,CAAC,CAAA,GAAgB,CAAA,CAAE,CAAC,CAAA;AAClE,EAAA,OAAO,IAAA,KAAS,CAAA;AAClB;ACGO,IAAM,aAAA,GAAgB;AAE7B,IAAM,WAAA,GAAc,CAAA;AACpB,IAAM,WAAA,GAAc,CAAA;AACpB,IAAM,aAAA,GAAgB,EAAA;AAEtB,SAAS,cAAA,CAAe,QAAmC,MAAA,EAAsB;AAC/E,EAAA,IAAI,MAAA,CAAO,WAAW,CAAA,EAAG;AACvB,IAAA,MAAM,IAAI,KAAA,CAAM,CAAA,EAAG,MAAM,CAAA,6DAAA,CAA4D,CAAA;AACvF,EAAA;AACA,EAAA,KAAA,IAAS,CAAA,GAAI,CAAA,EAAG,CAAA,GAAI,MAAA,CAAO,QAAQ,CAAA,EAAA,EAAK;AACtC,IAAA,MAAM,IAAA,GAAO,OAAO,CAAC,CAAA;AACrB,IAA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ACR,MAAA,sBAAA;AACA,MAAA;AAAA,KAAA;AAEJ,EAAA;AAEA,EAAA,MAAM,GAAA,GAAyB;IAC7B,MAAA,EAAQ,qBAAA;IACR,OAAA,EAAS,gBAAA;AACT,IAAA,IAAA;AACA,IAAA,MAAA;AACA,IAAA,SAAA;AACA,IAAA,GAAI,OAAA,KAAY,MAAA,GAAY,EAAE,OAAA,KAAY;AAAC,GAAA;AAE7C,EAAA,OAAO,GAAA;AACT","file":"index.js","sourcesContent":["// Isomorphic constant-time byte-equality. crypto-core is browser-safe by\n// design, so we cannot import `node:crypto.timingSafeEqual` — webpack rejects\n// the `node:` scheme in the browser bundle. A pure-JS XOR loop is constant-time\n// for equal-length inputs; length mismatch is a deliberate early-return (the\n// API surface itself leaks length, same as node's timingSafeEqual which throws).\nexport function compareCt(a: Uint8Array, b: Uint8Array): boolean {\n if (a.length !== b.length) return false;\n let diff = 0;\n // Lengths are equal and `i` stays in-bounds, so both indexes are always\n // defined — no nullish guard is needed (and one would read as a guard for\n // an impossible case).\n for (let i = 0; i < a.length; i++) diff |= (a[i] as number) ^ (b[i] as number);\n return diff === 0;\n}\n","// RFC 9162 §2.1.1 binary Merkle tree under SHA-256.\n// This implements the algorithm tier identified on the wire as the\n// `rfc9162-sha256` OPT-INFO; the record's `merkle[]` field carries the proof.\n//\n// Construction (RFC 9162 §2.1.1):\n// - Single leaf: MTH({d_0}) = SHA-256(0x00 || d_0)\n// - Internal node: MTH(L) = SHA-256(0x01 || MTH(L[0:k]) || MTH(L[k:n]))\n// where k = largest power of 2 strictly less than n.\n// - Empty trees (n == 0) are FORBIDDEN.\n// - The 0x00 leaf / 0x01 internal prefixes prevent the CVE-2012-2459\n// leaf-vs-internal collision family.\n\nimport { sha256 } from '@noble/hashes/sha2.js';\n\nimport { compareCt } from '../util/compare-ct';\n\nexport const MERKLE_ALG_ID = 'rfc9162-sha256' as const;\n\nconst LEAF_PREFIX = 0x00;\nconst NODE_PREFIX = 0x01;\nconst DIGEST_LENGTH = 32;\n\nfunction validateLeaves(leaves: ReadonlyArray<Uint8Array>, fnName: string): void {\n if (leaves.length === 0) {\n throw new Error(`${fnName}: empty leaf list (n == 0 is forbidden by RFC 9162 §2.1.1)`);\n }\n for (let i = 0; i < leaves.length; i++) {\n const leaf = leaves[i];\n if (!(leaf instanceof Uint8Array) || leaf.length !== DIGEST_LENGTH) {\n throw new Error(\n `${fnName}: leaf[${i}] must be a Uint8Array(${DIGEST_LENGTH}); got length ${\n leaf instanceof Uint8Array ? leaf.length : 'non-Uint8Array'\n }`,\n );\n }\n }\n}\n\nexport function merkleSha2256Root(leaves: ReadonlyArray<Uint8Array>): Uint8Array {\n validateLeaves(leaves, 'merkleSha2256Root');\n return mthRecursive(leaves, 0, leaves.length);\n}\n\nexport function merkleSha2256InclusionProof(\n leaves: ReadonlyArray<Uint8Array>,\n index: number,\n): Uint8Array[] {\n validateLeaves(leaves, 'merkleSha2256InclusionProof');\n if (!Number.isInteger(index) || index < 0 || index >= leaves.length) {\n throw new Error(\n `merkleSha2256InclusionProof: index ${index} out of range [0, ${leaves.length})`,\n );\n }\n return auditPath(leaves, index, 0, leaves.length);\n}\n\n/**\n * Verify an inclusion proof per RFC 9162 §2.1.3.2 (iterative form).\n *\n * `proof` is ordered leaf-to-root: `proof[0]` is the sibling at the leaf\n * level, `proof[m-1]` is the top-level sibling. The fold uses the\n * `sn`/`fn` tracking from RFC 9162: `sn` is the leaf index within the\n * current subtree, `fn` is (subtree_size - 1). At each step, `sn` odd\n * OR `sn == fn` means the current node is a right child (sibling on\n * the left); otherwise it is a left child (sibling on the right).\n * Both shift right by one each iteration. This handles non-power-of-2\n * sizes including the \"promote a lone right subtree\" cases.\n */\nexport function merkleSha2256VerifyInclusion(\n leaf: Uint8Array,\n index: number,\n treeSize: number,\n proof: ReadonlyArray<Uint8Array>,\n root: Uint8Array,\n): boolean {\n if (!(leaf instanceof Uint8Array) || leaf.length !== DIGEST_LENGTH) return false;\n if (!(root instanceof Uint8Array) || root.length !== DIGEST_LENGTH) return false;\n if (\n !Number.isInteger(index) ||\n !Number.isInteger(treeSize) ||\n treeSize < 1 ||\n index < 0 ||\n index >= treeSize\n ) {\n return false;\n }\n for (let i = 0; i < proof.length; i++) {\n const sibling = proof[i];\n if (!(sibling instanceof Uint8Array) || sibling.length !== DIGEST_LENGTH) {\n return false;\n }\n }\n\n if (treeSize === 1) {\n if (proof.length !== 0 || index !== 0) return false;\n return compareCt(hashLeaf(leaf), root);\n }\n\n let h = hashLeaf(leaf);\n let sn = index;\n let fn = treeSize - 1;\n for (let i = 0; i < proof.length; i++) {\n if (fn === 0) return false;\n const sibling = proof[i] as Uint8Array;\n if ((sn & 1) === 1 || sn === fn) {\n h = hashNode(sibling, h);\n while ((sn & 1) === 0 && sn !== 0) {\n sn >>>= 1;\n fn >>>= 1;\n }\n } else {\n h = hashNode(h, sibling);\n }\n sn >>>= 1;\n fn >>>= 1;\n }\n if (fn !== 0) return false;\n return compareCt(h, root);\n}\n\nfunction largestPow2Lt(n: number): number {\n let k = 1;\n while (k * 2 < n) k *= 2;\n return k;\n}\n\nfunction hashLeaf(d: Uint8Array): Uint8Array {\n const buf = new Uint8Array(1 + d.length);\n buf[0] = LEAF_PREFIX;\n buf.set(d, 1);\n return sha256(buf);\n}\n\nfunction hashNode(left: Uint8Array, right: Uint8Array): Uint8Array {\n const buf = new Uint8Array(1 + left.length + right.length);\n buf[0] = NODE_PREFIX;\n buf.set(left, 1);\n buf.set(right, 1 + left.length);\n return sha256(buf);\n}\n\nfunction mthRecursive(leaves: ReadonlyArray<Uint8Array>, start: number, end: number): Uint8Array {\n const n = end - start;\n if (n === 1) {\n return hashLeaf(leaves[start] as Uint8Array);\n }\n const k = largestPow2Lt(n);\n const left = mthRecursive(leaves, start, start + k);\n const right = mthRecursive(leaves, start + k, end);\n return hashNode(left, right);\n}\n\nfunction auditPath(\n leaves: ReadonlyArray<Uint8Array>,\n i: number,\n start: number,\n end: number,\n): Uint8Array[] {\n const n = end - start;\n if (n === 1) return [];\n const k = largestPow2Lt(n);\n if (i < k) {\n const subPath = auditPath(leaves, i, start, start + k);\n subPath.push(mthRecursive(leaves, start + k, end));\n return subPath;\n }\n const subPath = auditPath(leaves, i - k, start + k, end);\n subPath.push(mthRecursive(leaves, start, start + k));\n return subPath;\n}\n","// Every canonical-CBOR decode violation collapses to the single public CIP-309\n// taxonomy code MALFORMED_CBOR: indefinite-length (streaming) items, duplicate\n// keys, unsorted keys, non-minimal integer encodings, and invalid UTF-8 in text\n// strings. The taxonomy intentionally has one code for all of these; the\n// specific cause survives in the human-readable error message, not as a\n// separate code.\nexport type CanonicalCborErrorCode = 'MALFORMED_CBOR';\n\nexport class CanonicalCborError extends Error {\n readonly code: CanonicalCborErrorCode;\n\n constructor(code: CanonicalCborErrorCode, message: string, options?: { cause?: unknown }) {\n super(message, options);\n this.name = 'CanonicalCborError';\n this.code = code;\n }\n}\n","import { cdeDecodeOptions, decode, encode } from 'cbor2';\nimport { sortCoreDeterministic } from 'cbor2/sorts';\n\nimport { CanonicalCborError } from './errors';\n\nexport type CanonicalCborValue =\n | null\n | boolean\n | number\n | bigint\n | string\n | Uint8Array\n | readonly CanonicalCborValue[]\n | { readonly [key: string]: CanonicalCborValue }\n | ReadonlyMap<string | number, CanonicalCborValue>;\n\nexport function encodeCanonicalCbor(value: CanonicalCborValue): Uint8Array {\n return encode(value, {\n cde: true,\n collapseBigInts: true,\n rejectDuplicateKeys: true,\n sortKeys: sortCoreDeterministic,\n });\n}\n\nexport function decodeCanonicalCbor(bytes: Uint8Array): unknown {\n try {\n return decode(bytes, {\n ...cdeDecodeOptions,\n rejectStreaming: true,\n rejectDuplicateKeys: true,\n // A CIP-309 record carries integers, byte/text strings, arrays, maps and\n // `null` — and nothing else. Without these rejections the major-type-7\n // surface leaks into the decoder: a float16/32/64 that happens to hold an\n // integral value (e.g. 1.0) silently decodes to the integer 1 and passes\n // a `z.literal(1)` / Number.isInteger schema check, so two byte strings\n // that are NOT byte-identical canonicalise to the same record. That\n // breaks the cross-implementation parity invariant (the Python twin\n // already rejects non-integer `v` / `enc.scheme` outright). Reject the\n // whole non-record surface — floats, negative zero, undefined, and\n // non-{true,false,null} simple values — so any such input surfaces as\n // MALFORMED_CBOR via mapDecodeError rather than decoding to a look-alike.\n rejectFloats: true,\n rejectNegativeZero: true,\n rejectUndefined: true,\n rejectSimple: true,\n });\n } catch (cause) {\n throw mapDecodeError(cause);\n }\n}\n\nfunction mapDecodeError(cause: unknown): CanonicalCborError {\n const message = cause instanceof Error ? cause.message : String(cause);\n const lower = message.toLowerCase();\n // Every canonical-decode violation collapses to the single public taxonomy\n // code MALFORMED_CBOR: indefinite-length (streaming) items, duplicate keys,\n // non-canonical (unsorted) key ordering, non-minimal integer encodings, and\n // invalid UTF-8 in text strings. cbor2 raises the SAME \"Duplicate or out of\n // order key\" message for both true duplicates AND distinct-but-unsorted keys,\n // so the two are indistinguishable by message — and per the CIP-309 taxonomy\n // both belong under MALFORMED_CBOR anyway. The specific cause survives in the\n // human-readable message below; for indefinite-length we state it explicitly\n // so the diagnostic is not lost when the code is collapsed.\n const isIndefinite = lower.includes('streaming') || lower.includes('indefinite');\n const detail = isIndefinite\n ? `indefinite-length items are not permitted in canonical CBOR: ${message}`\n : message;\n return new CanonicalCborError('MALFORMED_CBOR', `cbor decode failed: ${detail}`, { cause });\n}\n","// Canonical-CBOR codec for the off-chain Merkle leaves-list artefact.\n// The on-chain `merkle[]` field binds to this file via `uris[]` / `leaf_count`;\n// the file itself carries the full leaf set. Canonical CBOR is RFC 8949 §4.2.1.\n//\n// CDDL:\n//\n// leaves-list = {\n// \"format\": \"cardano-poe-merkle-leaves-v1\",\n// \"tree_alg\": \"rfc9162-sha256\",\n// \"root\": bytes .size 32,\n// \"leaves\": [ + bytes .size 32 ],\n// \"leaf_count\": uint,\n// ? \"leaf_alg\": tstr,\n// }\n//\n// Canonical ordering is bytewise-lexicographic on encoded map keys (RFC 8949\n// §4.2.1) so the wire-key order is fixed by `cde:true` regardless of insertion\n// order: root (4B) < format (6B) < leaves (6B) < leaf_alg (8B) < tree_alg (8B)\n// < leaf_count (10B).\n\nimport { decodeCanonicalCbor, encodeCanonicalCbor } from '../cbor/canonical';\nimport { compareCt } from '../util/compare-ct';\nimport { merkleSha2256Root } from '../hash/merkle-sha2-256';\n\nexport const LEAVES_LIST_FORMAT_V1 = 'cardano-poe-merkle-leaves-v1' as const;\nconst TREE_ALG_RFC9162 = 'rfc9162-sha256' as const;\nconst DIGEST_LENGTH = 32;\nconst REGISTERED_FORMATS = new Set<string>([LEAVES_LIST_FORMAT_V1]);\n\nexport type MerkleLeavesListErrorCode =\n | 'SCHEMA_MERKLE_LEAVES_FORMAT_UNSUPPORTED'\n | 'SCHEMA_MERKLE_LEAVES_MALFORMED'\n | 'SCHEMA_MERKLE_LEAF_COUNT_MISMATCH'\n | 'MERKLE_ROOT_MISMATCH';\n\nexport class MerkleLeavesListError extends Error {\n readonly code: MerkleLeavesListErrorCode;\n constructor(code: MerkleLeavesListErrorCode, message?: string) {\n super(message ? `${code}: ${message}` : code);\n this.code = code;\n this.name = 'MerkleLeavesListError';\n }\n}\n\nexport interface EncodeLeavesListArgs {\n readonly leaves: ReadonlyArray<Uint8Array>;\n readonly root: Uint8Array;\n readonly leafAlg?: string;\n}\n\nexport interface DecodedLeavesList {\n readonly format: typeof LEAVES_LIST_FORMAT_V1;\n readonly treeAlg: typeof TREE_ALG_RFC9162;\n readonly root: Uint8Array;\n readonly leaves: Uint8Array[];\n readonly leafCount: number;\n readonly leafAlg?: string;\n}\n\nexport function encodeLeavesList(args: EncodeLeavesListArgs): Uint8Array {\n if (!(args.root instanceof Uint8Array) || args.root.length !== DIGEST_LENGTH) {\n throw new MerkleLeavesListError(\n 'SCHEMA_MERKLE_LEAVES_MALFORMED',\n `root must be a Uint8Array(${DIGEST_LENGTH})`,\n );\n }\n if (args.leaves.length < 1) {\n throw new MerkleLeavesListError(\n 'SCHEMA_MERKLE_LEAVES_MALFORMED',\n 'leaves array must be non-empty',\n );\n }\n const leavesCopy: Uint8Array[] = [];\n for (let i = 0; i < args.leaves.length; i++) {\n const leaf = args.leaves[i];\n if (!(leaf instanceof Uint8Array) || leaf.length !== DIGEST_LENGTH) {\n throw new MerkleLeavesListError(\n 'SCHEMA_MERKLE_LEAVES_MALFORMED',\n `leaves[${i}] must be a Uint8Array(${DIGEST_LENGTH})`,\n );\n }\n leavesCopy.push(leaf);\n }\n if (args.leafAlg !== undefined && typeof args.leafAlg !== 'string') {\n throw new MerkleLeavesListError(\n 'SCHEMA_MERKLE_LEAVES_MALFORMED',\n 'leaf_alg must be a string when present',\n );\n }\n const map: Record<string, unknown> = {\n format: LEAVES_LIST_FORMAT_V1,\n tree_alg: TREE_ALG_RFC9162,\n root: args.root,\n leaves: leavesCopy,\n leaf_count: leavesCopy.length,\n };\n if (args.leafAlg !== undefined) {\n map['leaf_alg'] = args.leafAlg;\n }\n return encodeCanonicalCbor(map as never);\n}\n\nexport function decodeLeavesList(bytes: Uint8Array): DecodedLeavesList {\n const decoded = decodeCanonicalCbor(bytes);\n if (typeof decoded !== 'object' || decoded === null || Array.isArray(decoded)) {\n throw new MerkleLeavesListError(\n 'SCHEMA_MERKLE_LEAVES_MALFORMED',\n 'leaves-list MUST be a CBOR map',\n );\n }\n const m = decoded as Record<string, unknown>;\n\n const format = m['format'];\n if (typeof format !== 'string') {\n throw new MerkleLeavesListError(\n 'SCHEMA_MERKLE_LEAVES_MALFORMED',\n 'format must be a text string',\n );\n }\n if (!REGISTERED_FORMATS.has(format)) {\n throw new MerkleLeavesListError(\n 'SCHEMA_MERKLE_LEAVES_FORMAT_UNSUPPORTED',\n `format '${format}' is not in the registered set`,\n );\n }\n\n const treeAlg = m['tree_alg'];\n if (treeAlg !== TREE_ALG_RFC9162) {\n throw new MerkleLeavesListError(\n 'SCHEMA_MERKLE_LEAVES_MALFORMED',\n `tree_alg '${String(treeAlg)}' is not '${TREE_ALG_RFC9162}'`,\n );\n }\n\n const root = m['root'];\n if (!(root instanceof Uint8Array) || root.length !== DIGEST_LENGTH) {\n throw new MerkleLeavesListError(\n 'SCHEMA_MERKLE_LEAVES_MALFORMED',\n `root must be a ${DIGEST_LENGTH}-byte byte string`,\n );\n }\n\n const leavesRaw = m['leaves'];\n if (!Array.isArray(leavesRaw) || leavesRaw.length < 1) {\n throw new MerkleLeavesListError(\n 'SCHEMA_MERKLE_LEAVES_MALFORMED',\n 'leaves must be a non-empty array',\n );\n }\n const leaves: Uint8Array[] = [];\n for (let i = 0; i < leavesRaw.length; i++) {\n const leaf = leavesRaw[i];\n if (!(leaf instanceof Uint8Array) || leaf.length !== DIGEST_LENGTH) {\n throw new MerkleLeavesListError(\n 'SCHEMA_MERKLE_LEAVES_MALFORMED',\n `leaves[${i}] must be a ${DIGEST_LENGTH}-byte byte string`,\n );\n }\n leaves.push(leaf);\n }\n\n const leafCountRaw = m['leaf_count'];\n let leafCount: number;\n if (typeof leafCountRaw === 'number' && Number.isInteger(leafCountRaw) && leafCountRaw >= 0) {\n leafCount = leafCountRaw;\n } else if (typeof leafCountRaw === 'bigint' && leafCountRaw >= 0n) {\n if (leafCountRaw > BigInt(Number.MAX_SAFE_INTEGER)) {\n throw new MerkleLeavesListError(\n 'SCHEMA_MERKLE_LEAVES_MALFORMED',\n 'leaf_count exceeds Number.MAX_SAFE_INTEGER',\n );\n }\n leafCount = Number(leafCountRaw);\n } else {\n throw new MerkleLeavesListError(\n 'SCHEMA_MERKLE_LEAVES_MALFORMED',\n 'leaf_count must be a non-negative CBOR uint',\n );\n }\n if (leaves.length !== leafCount) {\n throw new MerkleLeavesListError(\n 'SCHEMA_MERKLE_LEAF_COUNT_MISMATCH',\n `leaves.length (${leaves.length}) != leaf_count (${leafCount})`,\n );\n }\n\n let leafAlg: string | undefined;\n if (m['leaf_alg'] !== undefined) {\n if (typeof m['leaf_alg'] !== 'string') {\n throw new MerkleLeavesListError(\n 'SCHEMA_MERKLE_LEAVES_MALFORMED',\n 'leaf_alg must be a text string when present',\n );\n }\n leafAlg = m['leaf_alg'];\n }\n\n const recomputed = merkleSha2256Root(leaves);\n if (!compareCt(recomputed, root)) {\n throw new MerkleLeavesListError(\n 'MERKLE_ROOT_MISMATCH',\n 'leaves recompute does not match declared root',\n );\n }\n\n const out: DecodedLeavesList = {\n format: LEAVES_LIST_FORMAT_V1,\n treeAlg: TREE_ALG_RFC9162,\n root,\n leaves,\n leafCount,\n ...(leafAlg !== undefined ? { leafAlg } : {}),\n };\n return out;\n}\n"]}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { ValidationIssue, PoeRecord } from '@cardanowall/poe-standard';
|
|
2
|
+
import { H as HttpCallRecord, F as FetchOutbound } from './fetch-outbound-BT5-NiYN.js';
|
|
3
|
+
|
|
4
|
+
type Verdict = 'valid' | 'pending' | 'failed';
|
|
5
|
+
type ExitCode = 0 | 1 | 2 | 3;
|
|
6
|
+
type Profile = 'core' | 'signed' | 'sealed' | 'recipient-sealed';
|
|
7
|
+
type Network = 'cardano:mainnet';
|
|
8
|
+
declare const PROFILE_RANK: Readonly<Record<Profile, number>>;
|
|
9
|
+
|
|
10
|
+
interface VerifyTxInput {
|
|
11
|
+
readonly txHash: string;
|
|
12
|
+
readonly profile?: Profile;
|
|
13
|
+
readonly cardanoGatewayChain?: ReadonlyArray<string>;
|
|
14
|
+
readonly blockfrostProjectId?: string;
|
|
15
|
+
readonly arweaveGatewayChain?: ReadonlyArray<string>;
|
|
16
|
+
readonly ipfsGatewayChain?: ReadonlyArray<string>;
|
|
17
|
+
readonly confirmationDepthThreshold?: number;
|
|
18
|
+
readonly denyHosts?: ReadonlyArray<string>;
|
|
19
|
+
readonly verifyMerkle?: boolean;
|
|
20
|
+
readonly decryption?: ReadonlyArray<{
|
|
21
|
+
readonly itemIndex: number;
|
|
22
|
+
readonly recipientSecretKey: Uint8Array;
|
|
23
|
+
} | {
|
|
24
|
+
readonly itemIndex: number;
|
|
25
|
+
readonly passphrase: string;
|
|
26
|
+
}>;
|
|
27
|
+
readonly ciphertextBytes?: Readonly<Record<number, Uint8Array>>;
|
|
28
|
+
readonly merkleLeaves?: Readonly<Record<number, Uint8Array>>;
|
|
29
|
+
readonly cardanoNetwork?: 'mainnet' | 'preprod';
|
|
30
|
+
readonly fetchOutbound?: FetchOutbound;
|
|
31
|
+
}
|
|
32
|
+
type SignatureVerdict = 'valid' | 'invalid' | 'unsupported' | 'unresolved';
|
|
33
|
+
type SignatureFailureReason = 'MALFORMED_SIG_COSE_SIGN1' | 'SIGNATURE_UNSUPPORTED' | 'SIGNER_KEY_UNRESOLVED' | 'SIGNATURE_INVALID' | 'WALLET_ADDRESS_MISMATCH';
|
|
34
|
+
type SignerType = 'in-signature-kid' | 'wallet-inline-key';
|
|
35
|
+
interface VerifyRecordSignature {
|
|
36
|
+
readonly index: number;
|
|
37
|
+
readonly verdict: SignatureVerdict;
|
|
38
|
+
readonly signer_pub?: string;
|
|
39
|
+
readonly signer_type?: SignerType;
|
|
40
|
+
readonly reason?: SignatureFailureReason;
|
|
41
|
+
}
|
|
42
|
+
type DecryptionVerdict = 'decrypted' | 'wrong-key' | 'tampered-header' | 'tampered-ciphertext' | 'wrong-input-shape' | 'no-enc-envelope' | 'ciphertext-unavailable' | 'content-unavailable' | 'skipped' | 'kdf-failed';
|
|
43
|
+
interface VerifyItemDecryption {
|
|
44
|
+
readonly item_index: number;
|
|
45
|
+
readonly verdict: DecryptionVerdict;
|
|
46
|
+
readonly plaintext_hash_ok?: boolean;
|
|
47
|
+
readonly reason?: string;
|
|
48
|
+
}
|
|
49
|
+
type ItemHashCheck = {
|
|
50
|
+
readonly item_index: number;
|
|
51
|
+
readonly alg: string;
|
|
52
|
+
readonly ok: boolean;
|
|
53
|
+
};
|
|
54
|
+
type MerkleVerdict = 'valid' | 'mismatch' | 'unavailable' | 'format-unsupported' | 'unsupported';
|
|
55
|
+
interface VerifyMerkleCheck {
|
|
56
|
+
readonly merkle_index: number;
|
|
57
|
+
readonly alg: string;
|
|
58
|
+
readonly verdict: MerkleVerdict;
|
|
59
|
+
readonly root_recomputed?: Uint8Array;
|
|
60
|
+
readonly reason?: string;
|
|
61
|
+
}
|
|
62
|
+
interface VerifyUriCheck {
|
|
63
|
+
readonly item_index: number;
|
|
64
|
+
readonly uri: string;
|
|
65
|
+
readonly ok: boolean;
|
|
66
|
+
readonly reason?: string;
|
|
67
|
+
}
|
|
68
|
+
interface VerifyTxWitness {
|
|
69
|
+
readonly type: 'vkey';
|
|
70
|
+
readonly vkey: string;
|
|
71
|
+
readonly key_hash: string;
|
|
72
|
+
readonly signature_valid: boolean;
|
|
73
|
+
}
|
|
74
|
+
interface VerifyTxOutput {
|
|
75
|
+
readonly address: string;
|
|
76
|
+
readonly lovelace: string;
|
|
77
|
+
}
|
|
78
|
+
interface VerifyTxSummary {
|
|
79
|
+
readonly fee_lovelace: string;
|
|
80
|
+
readonly input_count: number;
|
|
81
|
+
readonly output_count: number;
|
|
82
|
+
readonly outputs: ReadonlyArray<VerifyTxOutput>;
|
|
83
|
+
readonly total_output_lovelace: string;
|
|
84
|
+
readonly script_witness_count: number;
|
|
85
|
+
readonly invalid_before?: number;
|
|
86
|
+
readonly invalid_hereafter?: number;
|
|
87
|
+
readonly required_signer_key_hashes?: ReadonlyArray<string>;
|
|
88
|
+
readonly network_id?: number;
|
|
89
|
+
}
|
|
90
|
+
interface VerifyReport {
|
|
91
|
+
readonly tx_hash: string;
|
|
92
|
+
readonly network: Network;
|
|
93
|
+
readonly verdict: Verdict;
|
|
94
|
+
readonly exit_code: ExitCode;
|
|
95
|
+
readonly profile: Profile;
|
|
96
|
+
readonly num_confirmations: number;
|
|
97
|
+
readonly confirmation_depth_threshold: number;
|
|
98
|
+
readonly block_time?: number;
|
|
99
|
+
readonly block_slot?: number;
|
|
100
|
+
readonly metadata_present: boolean;
|
|
101
|
+
readonly validation: {
|
|
102
|
+
readonly valid: boolean;
|
|
103
|
+
readonly issues?: ReadonlyArray<ValidationIssue>;
|
|
104
|
+
readonly warnings?: ReadonlyArray<ValidationIssue>;
|
|
105
|
+
readonly info?: ReadonlyArray<ValidationIssue>;
|
|
106
|
+
};
|
|
107
|
+
readonly record?: PoeRecord;
|
|
108
|
+
readonly record_signatures?: ReadonlyArray<VerifyRecordSignature>;
|
|
109
|
+
readonly tx_witnesses?: ReadonlyArray<VerifyTxWitness>;
|
|
110
|
+
readonly tx_summary?: VerifyTxSummary;
|
|
111
|
+
readonly metadata_labels?: ReadonlyArray<number>;
|
|
112
|
+
readonly item_hash_checks?: ReadonlyArray<ItemHashCheck>;
|
|
113
|
+
readonly item_decryptions?: ReadonlyArray<VerifyItemDecryption>;
|
|
114
|
+
readonly merkle_checks?: ReadonlyArray<VerifyMerkleCheck>;
|
|
115
|
+
readonly uri_checks?: ReadonlyArray<VerifyUriCheck>;
|
|
116
|
+
readonly supersedes_resolved?: {
|
|
117
|
+
readonly tx: string;
|
|
118
|
+
readonly exists: boolean;
|
|
119
|
+
};
|
|
120
|
+
readonly http_calls: ReadonlyArray<HttpCallRecord>;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export { type DecryptionVerdict as D, type ExitCode as E, type ItemHashCheck as I, type MerkleVerdict as M, type Network as N, PROFILE_RANK as P, type SignatureFailureReason as S, type Verdict as V, type Profile as a, type SignatureVerdict as b, type SignerType as c, type VerifyItemDecryption as d, type VerifyMerkleCheck as e, type VerifyRecordSignature as f, type VerifyReport as g, type VerifyTxInput as h, type VerifyTxOutput as i, type VerifyTxSummary as j, type VerifyTxWitness as k, type VerifyUriCheck as l };
|