@nexart/ai-execution 0.4.2 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +56 -2
- package/dist/index.cjs +1125 -10
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +28 -3
- package/dist/index.d.ts +28 -3
- package/dist/index.mjs +1121 -10
- package/dist/index.mjs.map +1 -1
- package/dist/providers/anthropic.cjs +1 -1
- package/dist/providers/anthropic.cjs.map +1 -1
- package/dist/providers/anthropic.d.cts +1 -1
- package/dist/providers/anthropic.d.ts +1 -1
- package/dist/providers/anthropic.mjs +1 -1
- package/dist/providers/anthropic.mjs.map +1 -1
- package/dist/providers/openai.cjs +1 -1
- package/dist/providers/openai.cjs.map +1 -1
- package/dist/providers/openai.d.cts +1 -1
- package/dist/providers/openai.d.ts +1 -1
- package/dist/providers/openai.mjs +1 -1
- package/dist/providers/openai.mjs.map +1 -1
- package/dist/providers/wrap.cjs +1 -1
- package/dist/providers/wrap.cjs.map +1 -1
- package/dist/providers/wrap.d.cts +1 -1
- package/dist/providers/wrap.d.ts +1 -1
- package/dist/providers/wrap.mjs +1 -1
- package/dist/providers/wrap.mjs.map +1 -1
- package/dist/{types-Cnm2G_rg.d.cts → types-BjEqrksn.d.cts} +39 -1
- package/dist/{types-Cnm2G_rg.d.ts → types-BjEqrksn.d.ts} +39 -1
- package/fixtures/attestation/keys-v1.json +18 -0
- package/fixtures/attestation/receipt-v1.json +10 -0
- package/fixtures/attestation/receipt-v1.pub +1 -0
- package/fixtures/attestation/receipt-v1.sig +1 -0
- package/package.json +6 -4
package/dist/index.cjs
CHANGED
|
@@ -42,6 +42,7 @@ __export(src_exports, {
|
|
|
42
42
|
computeOutputHash: () => computeOutputHash,
|
|
43
43
|
createSnapshot: () => createSnapshot,
|
|
44
44
|
exportCer: () => exportCer,
|
|
45
|
+
fetchNodeKeys: () => fetchNodeKeys,
|
|
45
46
|
getAttestationReceipt: () => getAttestationReceipt,
|
|
46
47
|
hasAttestation: () => hasAttestation,
|
|
47
48
|
hashCanonicalJson: () => hashCanonicalJson,
|
|
@@ -49,10 +50,13 @@ __export(src_exports, {
|
|
|
49
50
|
importCer: () => importCer,
|
|
50
51
|
sanitizeForAttestation: () => sanitizeForAttestation,
|
|
51
52
|
sealCer: () => sealCer,
|
|
53
|
+
selectNodeKey: () => selectNodeKey,
|
|
52
54
|
sha256Hex: () => sha256Hex,
|
|
53
55
|
toCanonicalJson: () => toCanonicalJson,
|
|
54
56
|
verify: () => verifyCer,
|
|
57
|
+
verifyBundleAttestation: () => verifyBundleAttestation,
|
|
55
58
|
verifyCer: () => verifyCer,
|
|
59
|
+
verifyNodeReceiptSignature: () => verifyNodeReceiptSignature,
|
|
56
60
|
verifySnapshot: () => verifySnapshot,
|
|
57
61
|
wrapProvider: () => wrapProvider
|
|
58
62
|
});
|
|
@@ -68,7 +72,11 @@ var CerVerifyCode = {
|
|
|
68
72
|
INVALID_SHA256_FORMAT: "INVALID_SHA256_FORMAT",
|
|
69
73
|
CANONICALIZATION_ERROR: "CANONICALIZATION_ERROR",
|
|
70
74
|
SCHEMA_ERROR: "SCHEMA_ERROR",
|
|
71
|
-
UNKNOWN_ERROR: "UNKNOWN_ERROR"
|
|
75
|
+
UNKNOWN_ERROR: "UNKNOWN_ERROR",
|
|
76
|
+
ATTESTATION_MISSING: "ATTESTATION_MISSING",
|
|
77
|
+
ATTESTATION_KEY_NOT_FOUND: "ATTESTATION_KEY_NOT_FOUND",
|
|
78
|
+
ATTESTATION_INVALID_SIGNATURE: "ATTESTATION_INVALID_SIGNATURE",
|
|
79
|
+
ATTESTATION_KEY_FORMAT_UNSUPPORTED: "ATTESTATION_KEY_FORMAT_UNSUPPORTED"
|
|
72
80
|
};
|
|
73
81
|
|
|
74
82
|
// src/errors.ts
|
|
@@ -164,7 +172,7 @@ function computeOutputHash(output) {
|
|
|
164
172
|
}
|
|
165
173
|
|
|
166
174
|
// src/snapshot.ts
|
|
167
|
-
var PACKAGE_VERSION = "0.
|
|
175
|
+
var PACKAGE_VERSION = "0.5.0";
|
|
168
176
|
function validateParameters(params) {
|
|
169
177
|
const errors = [];
|
|
170
178
|
if (typeof params.temperature !== "number" || !Number.isFinite(params.temperature)) {
|
|
@@ -350,8 +358,8 @@ function verifyCer(bundle) {
|
|
|
350
358
|
let snapshotResult = null;
|
|
351
359
|
try {
|
|
352
360
|
snapshotResult = verifySnapshot(bundle.snapshot);
|
|
353
|
-
} catch (
|
|
354
|
-
canonicalizationError =
|
|
361
|
+
} catch (err2) {
|
|
362
|
+
canonicalizationError = err2 instanceof Error ? err2.message : String(err2);
|
|
355
363
|
}
|
|
356
364
|
if (canonicalizationError !== null) {
|
|
357
365
|
const errors2 = [...schemaErrors, ...formatErrors, canonicalizationError];
|
|
@@ -370,8 +378,8 @@ function verifyCer(bundle) {
|
|
|
370
378
|
if (bundle.certificateHash !== expectedHash) {
|
|
371
379
|
certHashErrors.push(`certificateHash mismatch: expected ${expectedHash}, got ${bundle.certificateHash}`);
|
|
372
380
|
}
|
|
373
|
-
} catch (
|
|
374
|
-
const msg =
|
|
381
|
+
} catch (err2) {
|
|
382
|
+
const msg = err2 instanceof Error ? err2.message : String(err2);
|
|
375
383
|
const errors2 = [...schemaErrors, ...formatErrors, ...snapshotErrors, msg];
|
|
376
384
|
return { ok: false, errors: errors2, code: CerVerifyCode.CANONICALIZATION_ERROR, details: [msg] };
|
|
377
385
|
}
|
|
@@ -558,9 +566,9 @@ async function attest(bundle, options) {
|
|
|
558
566
|
body: JSON.stringify(sanitized),
|
|
559
567
|
signal: controller.signal
|
|
560
568
|
});
|
|
561
|
-
} catch (
|
|
569
|
+
} catch (err2) {
|
|
562
570
|
clearTimeout(timer);
|
|
563
|
-
const error =
|
|
571
|
+
const error = err2;
|
|
564
572
|
if (error.name === "AbortError") {
|
|
565
573
|
throw new CerAttestationError(
|
|
566
574
|
`Attestation request timed out after ${timeoutMs}ms`
|
|
@@ -630,8 +638,8 @@ function importCer(json) {
|
|
|
630
638
|
let parsed;
|
|
631
639
|
try {
|
|
632
640
|
parsed = JSON.parse(json);
|
|
633
|
-
} catch (
|
|
634
|
-
throw new CerVerificationError([`Invalid JSON: ${
|
|
641
|
+
} catch (err2) {
|
|
642
|
+
throw new CerVerificationError([`Invalid JSON: ${err2.message}`]);
|
|
635
643
|
}
|
|
636
644
|
const bundle = parsed;
|
|
637
645
|
if (!bundle || typeof bundle !== "object") {
|
|
@@ -695,6 +703,10 @@ function buildReceipt(obj) {
|
|
|
695
703
|
if (nodeId) receipt.nodeId = nodeId;
|
|
696
704
|
const attestedAt = extractStr(obj, "attestedAt");
|
|
697
705
|
if (attestedAt) receipt.attestedAt = attestedAt;
|
|
706
|
+
const attestorKeyId = extractStr(obj, "attestorKeyId");
|
|
707
|
+
if (attestorKeyId) receipt.attestorKeyId = attestorKeyId;
|
|
708
|
+
const signatureB64Url = extractStr(obj, "signature") ?? extractStr(obj, "signatureB64Url");
|
|
709
|
+
if (signatureB64Url) receipt.signatureB64Url = signatureB64Url;
|
|
698
710
|
return receipt;
|
|
699
711
|
}
|
|
700
712
|
function getAttestationReceipt(bundle) {
|
|
@@ -743,6 +755,1097 @@ async function attestIfNeeded(bundle, options) {
|
|
|
743
755
|
const receipt = receiptFromProof(proof, bundle);
|
|
744
756
|
return { bundle, receipt };
|
|
745
757
|
}
|
|
758
|
+
|
|
759
|
+
// node_modules/@noble/ed25519/index.js
|
|
760
|
+
var ed25519_CURVE = {
|
|
761
|
+
p: 0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffedn,
|
|
762
|
+
n: 0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3edn,
|
|
763
|
+
h: 8n,
|
|
764
|
+
a: 0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffecn,
|
|
765
|
+
d: 0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3n,
|
|
766
|
+
Gx: 0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51an,
|
|
767
|
+
Gy: 0x6666666666666666666666666666666666666666666666666666666666666658n
|
|
768
|
+
};
|
|
769
|
+
var { p: P, n: N, Gx, Gy, a: _a, d: _d, h } = ed25519_CURVE;
|
|
770
|
+
var L = 32;
|
|
771
|
+
var L2 = 64;
|
|
772
|
+
var captureTrace = (...args) => {
|
|
773
|
+
if ("captureStackTrace" in Error && typeof Error.captureStackTrace === "function") {
|
|
774
|
+
Error.captureStackTrace(...args);
|
|
775
|
+
}
|
|
776
|
+
};
|
|
777
|
+
var err = (message = "") => {
|
|
778
|
+
const e = new Error(message);
|
|
779
|
+
captureTrace(e, err);
|
|
780
|
+
throw e;
|
|
781
|
+
};
|
|
782
|
+
var isBig = (n) => typeof n === "bigint";
|
|
783
|
+
var isStr = (s) => typeof s === "string";
|
|
784
|
+
var isBytes = (a) => a instanceof Uint8Array || ArrayBuffer.isView(a) && a.constructor.name === "Uint8Array";
|
|
785
|
+
var abytes = (value, length, title = "") => {
|
|
786
|
+
const bytes = isBytes(value);
|
|
787
|
+
const len = value?.length;
|
|
788
|
+
const needsLen = length !== void 0;
|
|
789
|
+
if (!bytes || needsLen && len !== length) {
|
|
790
|
+
const prefix = title && `"${title}" `;
|
|
791
|
+
const ofLen = needsLen ? ` of length ${length}` : "";
|
|
792
|
+
const got = bytes ? `length=${len}` : `type=${typeof value}`;
|
|
793
|
+
err(prefix + "expected Uint8Array" + ofLen + ", got " + got);
|
|
794
|
+
}
|
|
795
|
+
return value;
|
|
796
|
+
};
|
|
797
|
+
var u8n = (len) => new Uint8Array(len);
|
|
798
|
+
var u8fr = (buf) => Uint8Array.from(buf);
|
|
799
|
+
var padh = (n, pad) => n.toString(16).padStart(pad, "0");
|
|
800
|
+
var bytesToHex = (b) => Array.from(abytes(b)).map((e) => padh(e, 2)).join("");
|
|
801
|
+
var C = { _0: 48, _9: 57, A: 65, F: 70, a: 97, f: 102 };
|
|
802
|
+
var _ch = (ch) => {
|
|
803
|
+
if (ch >= C._0 && ch <= C._9)
|
|
804
|
+
return ch - C._0;
|
|
805
|
+
if (ch >= C.A && ch <= C.F)
|
|
806
|
+
return ch - (C.A - 10);
|
|
807
|
+
if (ch >= C.a && ch <= C.f)
|
|
808
|
+
return ch - (C.a - 10);
|
|
809
|
+
return;
|
|
810
|
+
};
|
|
811
|
+
var hexToBytes = (hex) => {
|
|
812
|
+
const e = "hex invalid";
|
|
813
|
+
if (!isStr(hex))
|
|
814
|
+
return err(e);
|
|
815
|
+
const hl = hex.length;
|
|
816
|
+
const al = hl / 2;
|
|
817
|
+
if (hl % 2)
|
|
818
|
+
return err(e);
|
|
819
|
+
const array = u8n(al);
|
|
820
|
+
for (let ai = 0, hi = 0; ai < al; ai++, hi += 2) {
|
|
821
|
+
const n1 = _ch(hex.charCodeAt(hi));
|
|
822
|
+
const n2 = _ch(hex.charCodeAt(hi + 1));
|
|
823
|
+
if (n1 === void 0 || n2 === void 0)
|
|
824
|
+
return err(e);
|
|
825
|
+
array[ai] = n1 * 16 + n2;
|
|
826
|
+
}
|
|
827
|
+
return array;
|
|
828
|
+
};
|
|
829
|
+
var cr = () => globalThis?.crypto;
|
|
830
|
+
var subtle = () => cr()?.subtle ?? err("crypto.subtle must be defined, consider polyfill");
|
|
831
|
+
var concatBytes = (...arrs) => {
|
|
832
|
+
const r = u8n(arrs.reduce((sum, a) => sum + abytes(a).length, 0));
|
|
833
|
+
let pad = 0;
|
|
834
|
+
arrs.forEach((a) => {
|
|
835
|
+
r.set(a, pad);
|
|
836
|
+
pad += a.length;
|
|
837
|
+
});
|
|
838
|
+
return r;
|
|
839
|
+
};
|
|
840
|
+
var big = BigInt;
|
|
841
|
+
var assertRange = (n, min, max, msg = "bad number: out of range") => isBig(n) && min <= n && n < max ? n : err(msg);
|
|
842
|
+
var M = (a, b = P) => {
|
|
843
|
+
const r = a % b;
|
|
844
|
+
return r >= 0n ? r : b + r;
|
|
845
|
+
};
|
|
846
|
+
var modN = (a) => M(a, N);
|
|
847
|
+
var invert = (num, md) => {
|
|
848
|
+
if (num === 0n || md <= 0n)
|
|
849
|
+
err("no inverse n=" + num + " mod=" + md);
|
|
850
|
+
let a = M(num, md), b = md, x = 0n, y = 1n, u = 1n, v = 0n;
|
|
851
|
+
while (a !== 0n) {
|
|
852
|
+
const q = b / a, r = b % a;
|
|
853
|
+
const m = x - u * q, n = y - v * q;
|
|
854
|
+
b = a, a = r, x = u, y = v, u = m, v = n;
|
|
855
|
+
}
|
|
856
|
+
return b === 1n ? M(x, md) : err("no inverse");
|
|
857
|
+
};
|
|
858
|
+
var callHash = (name) => {
|
|
859
|
+
const fn = hashes[name];
|
|
860
|
+
if (typeof fn !== "function")
|
|
861
|
+
err("hashes." + name + " not set");
|
|
862
|
+
return fn;
|
|
863
|
+
};
|
|
864
|
+
var apoint = (p) => p instanceof Point ? p : err("Point expected");
|
|
865
|
+
var B256 = 2n ** 256n;
|
|
866
|
+
var Point = class _Point {
|
|
867
|
+
static BASE;
|
|
868
|
+
static ZERO;
|
|
869
|
+
X;
|
|
870
|
+
Y;
|
|
871
|
+
Z;
|
|
872
|
+
T;
|
|
873
|
+
constructor(X, Y, Z, T) {
|
|
874
|
+
const max = B256;
|
|
875
|
+
this.X = assertRange(X, 0n, max);
|
|
876
|
+
this.Y = assertRange(Y, 0n, max);
|
|
877
|
+
this.Z = assertRange(Z, 1n, max);
|
|
878
|
+
this.T = assertRange(T, 0n, max);
|
|
879
|
+
Object.freeze(this);
|
|
880
|
+
}
|
|
881
|
+
static CURVE() {
|
|
882
|
+
return ed25519_CURVE;
|
|
883
|
+
}
|
|
884
|
+
static fromAffine(p) {
|
|
885
|
+
return new _Point(p.x, p.y, 1n, M(p.x * p.y));
|
|
886
|
+
}
|
|
887
|
+
/** RFC8032 5.1.3: Uint8Array to Point. */
|
|
888
|
+
static fromBytes(hex, zip215 = false) {
|
|
889
|
+
const d = _d;
|
|
890
|
+
const normed = u8fr(abytes(hex, L));
|
|
891
|
+
const lastByte = hex[31];
|
|
892
|
+
normed[31] = lastByte & ~128;
|
|
893
|
+
const y = bytesToNumLE(normed);
|
|
894
|
+
const max = zip215 ? B256 : P;
|
|
895
|
+
assertRange(y, 0n, max);
|
|
896
|
+
const y2 = M(y * y);
|
|
897
|
+
const u = M(y2 - 1n);
|
|
898
|
+
const v = M(d * y2 + 1n);
|
|
899
|
+
let { isValid, value: x } = uvRatio(u, v);
|
|
900
|
+
if (!isValid)
|
|
901
|
+
err("bad point: y not sqrt");
|
|
902
|
+
const isXOdd = (x & 1n) === 1n;
|
|
903
|
+
const isLastByteOdd = (lastByte & 128) !== 0;
|
|
904
|
+
if (!zip215 && x === 0n && isLastByteOdd)
|
|
905
|
+
err("bad point: x==0, isLastByteOdd");
|
|
906
|
+
if (isLastByteOdd !== isXOdd)
|
|
907
|
+
x = M(-x);
|
|
908
|
+
return new _Point(x, y, 1n, M(x * y));
|
|
909
|
+
}
|
|
910
|
+
static fromHex(hex, zip215) {
|
|
911
|
+
return _Point.fromBytes(hexToBytes(hex), zip215);
|
|
912
|
+
}
|
|
913
|
+
get x() {
|
|
914
|
+
return this.toAffine().x;
|
|
915
|
+
}
|
|
916
|
+
get y() {
|
|
917
|
+
return this.toAffine().y;
|
|
918
|
+
}
|
|
919
|
+
/** Checks if the point is valid and on-curve. */
|
|
920
|
+
assertValidity() {
|
|
921
|
+
const a = _a;
|
|
922
|
+
const d = _d;
|
|
923
|
+
const p = this;
|
|
924
|
+
if (p.is0())
|
|
925
|
+
return err("bad point: ZERO");
|
|
926
|
+
const { X, Y, Z, T } = p;
|
|
927
|
+
const X2 = M(X * X);
|
|
928
|
+
const Y2 = M(Y * Y);
|
|
929
|
+
const Z2 = M(Z * Z);
|
|
930
|
+
const Z4 = M(Z2 * Z2);
|
|
931
|
+
const aX2 = M(X2 * a);
|
|
932
|
+
const left = M(Z2 * M(aX2 + Y2));
|
|
933
|
+
const right = M(Z4 + M(d * M(X2 * Y2)));
|
|
934
|
+
if (left !== right)
|
|
935
|
+
return err("bad point: equation left != right (1)");
|
|
936
|
+
const XY = M(X * Y);
|
|
937
|
+
const ZT = M(Z * T);
|
|
938
|
+
if (XY !== ZT)
|
|
939
|
+
return err("bad point: equation left != right (2)");
|
|
940
|
+
return this;
|
|
941
|
+
}
|
|
942
|
+
/** Equality check: compare points P&Q. */
|
|
943
|
+
equals(other) {
|
|
944
|
+
const { X: X1, Y: Y1, Z: Z1 } = this;
|
|
945
|
+
const { X: X2, Y: Y2, Z: Z2 } = apoint(other);
|
|
946
|
+
const X1Z2 = M(X1 * Z2);
|
|
947
|
+
const X2Z1 = M(X2 * Z1);
|
|
948
|
+
const Y1Z2 = M(Y1 * Z2);
|
|
949
|
+
const Y2Z1 = M(Y2 * Z1);
|
|
950
|
+
return X1Z2 === X2Z1 && Y1Z2 === Y2Z1;
|
|
951
|
+
}
|
|
952
|
+
is0() {
|
|
953
|
+
return this.equals(I);
|
|
954
|
+
}
|
|
955
|
+
/** Flip point over y coordinate. */
|
|
956
|
+
negate() {
|
|
957
|
+
return new _Point(M(-this.X), this.Y, this.Z, M(-this.T));
|
|
958
|
+
}
|
|
959
|
+
/** Point doubling. Complete formula. Cost: `4M + 4S + 1*a + 6add + 1*2`. */
|
|
960
|
+
double() {
|
|
961
|
+
const { X: X1, Y: Y1, Z: Z1 } = this;
|
|
962
|
+
const a = _a;
|
|
963
|
+
const A = M(X1 * X1);
|
|
964
|
+
const B = M(Y1 * Y1);
|
|
965
|
+
const C2 = M(2n * M(Z1 * Z1));
|
|
966
|
+
const D = M(a * A);
|
|
967
|
+
const x1y1 = X1 + Y1;
|
|
968
|
+
const E = M(M(x1y1 * x1y1) - A - B);
|
|
969
|
+
const G2 = D + B;
|
|
970
|
+
const F = G2 - C2;
|
|
971
|
+
const H = D - B;
|
|
972
|
+
const X3 = M(E * F);
|
|
973
|
+
const Y3 = M(G2 * H);
|
|
974
|
+
const T3 = M(E * H);
|
|
975
|
+
const Z3 = M(F * G2);
|
|
976
|
+
return new _Point(X3, Y3, Z3, T3);
|
|
977
|
+
}
|
|
978
|
+
/** Point addition. Complete formula. Cost: `8M + 1*k + 8add + 1*2`. */
|
|
979
|
+
add(other) {
|
|
980
|
+
const { X: X1, Y: Y1, Z: Z1, T: T1 } = this;
|
|
981
|
+
const { X: X2, Y: Y2, Z: Z2, T: T2 } = apoint(other);
|
|
982
|
+
const a = _a;
|
|
983
|
+
const d = _d;
|
|
984
|
+
const A = M(X1 * X2);
|
|
985
|
+
const B = M(Y1 * Y2);
|
|
986
|
+
const C2 = M(T1 * d * T2);
|
|
987
|
+
const D = M(Z1 * Z2);
|
|
988
|
+
const E = M((X1 + Y1) * (X2 + Y2) - A - B);
|
|
989
|
+
const F = M(D - C2);
|
|
990
|
+
const G2 = M(D + C2);
|
|
991
|
+
const H = M(B - a * A);
|
|
992
|
+
const X3 = M(E * F);
|
|
993
|
+
const Y3 = M(G2 * H);
|
|
994
|
+
const T3 = M(E * H);
|
|
995
|
+
const Z3 = M(F * G2);
|
|
996
|
+
return new _Point(X3, Y3, Z3, T3);
|
|
997
|
+
}
|
|
998
|
+
subtract(other) {
|
|
999
|
+
return this.add(apoint(other).negate());
|
|
1000
|
+
}
|
|
1001
|
+
/**
|
|
1002
|
+
* Point-by-scalar multiplication. Scalar must be in range 1 <= n < CURVE.n.
|
|
1003
|
+
* Uses {@link wNAF} for base point.
|
|
1004
|
+
* Uses fake point to mitigate side-channel leakage.
|
|
1005
|
+
* @param n scalar by which point is multiplied
|
|
1006
|
+
* @param safe safe mode guards against timing attacks; unsafe mode is faster
|
|
1007
|
+
*/
|
|
1008
|
+
multiply(n, safe = true) {
|
|
1009
|
+
if (!safe && (n === 0n || this.is0()))
|
|
1010
|
+
return I;
|
|
1011
|
+
assertRange(n, 1n, N);
|
|
1012
|
+
if (n === 1n)
|
|
1013
|
+
return this;
|
|
1014
|
+
if (this.equals(G))
|
|
1015
|
+
return wNAF(n).p;
|
|
1016
|
+
let p = I;
|
|
1017
|
+
let f = G;
|
|
1018
|
+
for (let d = this; n > 0n; d = d.double(), n >>= 1n) {
|
|
1019
|
+
if (n & 1n)
|
|
1020
|
+
p = p.add(d);
|
|
1021
|
+
else if (safe)
|
|
1022
|
+
f = f.add(d);
|
|
1023
|
+
}
|
|
1024
|
+
return p;
|
|
1025
|
+
}
|
|
1026
|
+
multiplyUnsafe(scalar) {
|
|
1027
|
+
return this.multiply(scalar, false);
|
|
1028
|
+
}
|
|
1029
|
+
/** Convert point to 2d xy affine point. (X, Y, Z) ∋ (x=X/Z, y=Y/Z) */
|
|
1030
|
+
toAffine() {
|
|
1031
|
+
const { X, Y, Z } = this;
|
|
1032
|
+
if (this.equals(I))
|
|
1033
|
+
return { x: 0n, y: 1n };
|
|
1034
|
+
const iz = invert(Z, P);
|
|
1035
|
+
if (M(Z * iz) !== 1n)
|
|
1036
|
+
err("invalid inverse");
|
|
1037
|
+
const x = M(X * iz);
|
|
1038
|
+
const y = M(Y * iz);
|
|
1039
|
+
return { x, y };
|
|
1040
|
+
}
|
|
1041
|
+
toBytes() {
|
|
1042
|
+
const { x, y } = this.assertValidity().toAffine();
|
|
1043
|
+
const b = numTo32bLE(y);
|
|
1044
|
+
b[31] |= x & 1n ? 128 : 0;
|
|
1045
|
+
return b;
|
|
1046
|
+
}
|
|
1047
|
+
toHex() {
|
|
1048
|
+
return bytesToHex(this.toBytes());
|
|
1049
|
+
}
|
|
1050
|
+
clearCofactor() {
|
|
1051
|
+
return this.multiply(big(h), false);
|
|
1052
|
+
}
|
|
1053
|
+
isSmallOrder() {
|
|
1054
|
+
return this.clearCofactor().is0();
|
|
1055
|
+
}
|
|
1056
|
+
isTorsionFree() {
|
|
1057
|
+
let p = this.multiply(N / 2n, false).double();
|
|
1058
|
+
if (N % 2n)
|
|
1059
|
+
p = p.add(this);
|
|
1060
|
+
return p.is0();
|
|
1061
|
+
}
|
|
1062
|
+
};
|
|
1063
|
+
var G = new Point(Gx, Gy, 1n, M(Gx * Gy));
|
|
1064
|
+
var I = new Point(0n, 1n, 1n, 0n);
|
|
1065
|
+
Point.BASE = G;
|
|
1066
|
+
Point.ZERO = I;
|
|
1067
|
+
var numTo32bLE = (num) => hexToBytes(padh(assertRange(num, 0n, B256), L2)).reverse();
|
|
1068
|
+
var bytesToNumLE = (b) => big("0x" + bytesToHex(u8fr(abytes(b)).reverse()));
|
|
1069
|
+
var pow2 = (x, power) => {
|
|
1070
|
+
let r = x;
|
|
1071
|
+
while (power-- > 0n) {
|
|
1072
|
+
r *= r;
|
|
1073
|
+
r %= P;
|
|
1074
|
+
}
|
|
1075
|
+
return r;
|
|
1076
|
+
};
|
|
1077
|
+
var pow_2_252_3 = (x) => {
|
|
1078
|
+
const x2 = x * x % P;
|
|
1079
|
+
const b2 = x2 * x % P;
|
|
1080
|
+
const b4 = pow2(b2, 2n) * b2 % P;
|
|
1081
|
+
const b5 = pow2(b4, 1n) * x % P;
|
|
1082
|
+
const b10 = pow2(b5, 5n) * b5 % P;
|
|
1083
|
+
const b20 = pow2(b10, 10n) * b10 % P;
|
|
1084
|
+
const b40 = pow2(b20, 20n) * b20 % P;
|
|
1085
|
+
const b80 = pow2(b40, 40n) * b40 % P;
|
|
1086
|
+
const b160 = pow2(b80, 80n) * b80 % P;
|
|
1087
|
+
const b240 = pow2(b160, 80n) * b80 % P;
|
|
1088
|
+
const b250 = pow2(b240, 10n) * b10 % P;
|
|
1089
|
+
const pow_p_5_8 = pow2(b250, 2n) * x % P;
|
|
1090
|
+
return { pow_p_5_8, b2 };
|
|
1091
|
+
};
|
|
1092
|
+
var RM1 = 0x2b8324804fc1df0b2b4d00993dfbd7a72f431806ad2fe478c4ee1b274a0ea0b0n;
|
|
1093
|
+
var uvRatio = (u, v) => {
|
|
1094
|
+
const v3 = M(v * v * v);
|
|
1095
|
+
const v7 = M(v3 * v3 * v);
|
|
1096
|
+
const pow = pow_2_252_3(u * v7).pow_p_5_8;
|
|
1097
|
+
let x = M(u * v3 * pow);
|
|
1098
|
+
const vx2 = M(v * x * x);
|
|
1099
|
+
const root1 = x;
|
|
1100
|
+
const root2 = M(x * RM1);
|
|
1101
|
+
const useRoot1 = vx2 === u;
|
|
1102
|
+
const useRoot2 = vx2 === M(-u);
|
|
1103
|
+
const noRoot = vx2 === M(-u * RM1);
|
|
1104
|
+
if (useRoot1)
|
|
1105
|
+
x = root1;
|
|
1106
|
+
if (useRoot2 || noRoot)
|
|
1107
|
+
x = root2;
|
|
1108
|
+
if ((M(x) & 1n) === 1n)
|
|
1109
|
+
x = M(-x);
|
|
1110
|
+
return { isValid: useRoot1 || useRoot2, value: x };
|
|
1111
|
+
};
|
|
1112
|
+
var modL_LE = (hash) => modN(bytesToNumLE(hash));
|
|
1113
|
+
var sha512s = (...m) => callHash("sha512")(concatBytes(...m));
|
|
1114
|
+
var hashFinishS = (res) => res.finish(sha512s(res.hashable));
|
|
1115
|
+
var defaultVerifyOpts = { zip215: true };
|
|
1116
|
+
var _verify = (sig, msg, pub, opts = defaultVerifyOpts) => {
|
|
1117
|
+
sig = abytes(sig, L2);
|
|
1118
|
+
msg = abytes(msg);
|
|
1119
|
+
pub = abytes(pub, L);
|
|
1120
|
+
const { zip215 } = opts;
|
|
1121
|
+
let A;
|
|
1122
|
+
let R;
|
|
1123
|
+
let s;
|
|
1124
|
+
let SB;
|
|
1125
|
+
let hashable = Uint8Array.of();
|
|
1126
|
+
try {
|
|
1127
|
+
A = Point.fromBytes(pub, zip215);
|
|
1128
|
+
R = Point.fromBytes(sig.slice(0, L), zip215);
|
|
1129
|
+
s = bytesToNumLE(sig.slice(L, L2));
|
|
1130
|
+
SB = G.multiply(s, false);
|
|
1131
|
+
hashable = concatBytes(R.toBytes(), A.toBytes(), msg);
|
|
1132
|
+
} catch (error) {
|
|
1133
|
+
}
|
|
1134
|
+
const finish = (hashed) => {
|
|
1135
|
+
if (SB == null)
|
|
1136
|
+
return false;
|
|
1137
|
+
if (!zip215 && A.isSmallOrder())
|
|
1138
|
+
return false;
|
|
1139
|
+
const k = modL_LE(hashed);
|
|
1140
|
+
const RkA = R.add(A.multiply(k, false));
|
|
1141
|
+
return RkA.add(SB.negate()).clearCofactor().is0();
|
|
1142
|
+
};
|
|
1143
|
+
return { hashable, finish };
|
|
1144
|
+
};
|
|
1145
|
+
var verify = (signature, message, publicKey, opts = defaultVerifyOpts) => hashFinishS(_verify(signature, message, publicKey, opts));
|
|
1146
|
+
var hashes = {
|
|
1147
|
+
sha512Async: async (message) => {
|
|
1148
|
+
const s = subtle();
|
|
1149
|
+
const m = concatBytes(message);
|
|
1150
|
+
return u8n(await s.digest("SHA-512", m.buffer));
|
|
1151
|
+
},
|
|
1152
|
+
sha512: void 0
|
|
1153
|
+
};
|
|
1154
|
+
var W = 8;
|
|
1155
|
+
var scalarBits = 256;
|
|
1156
|
+
var pwindows = Math.ceil(scalarBits / W) + 1;
|
|
1157
|
+
var pwindowSize = 2 ** (W - 1);
|
|
1158
|
+
var precompute = () => {
|
|
1159
|
+
const points = [];
|
|
1160
|
+
let p = G;
|
|
1161
|
+
let b = p;
|
|
1162
|
+
for (let w = 0; w < pwindows; w++) {
|
|
1163
|
+
b = p;
|
|
1164
|
+
points.push(b);
|
|
1165
|
+
for (let i = 1; i < pwindowSize; i++) {
|
|
1166
|
+
b = b.add(p);
|
|
1167
|
+
points.push(b);
|
|
1168
|
+
}
|
|
1169
|
+
p = b.double();
|
|
1170
|
+
}
|
|
1171
|
+
return points;
|
|
1172
|
+
};
|
|
1173
|
+
var Gpows = void 0;
|
|
1174
|
+
var ctneg = (cnd, p) => {
|
|
1175
|
+
const n = p.negate();
|
|
1176
|
+
return cnd ? n : p;
|
|
1177
|
+
};
|
|
1178
|
+
var wNAF = (n) => {
|
|
1179
|
+
const comp = Gpows || (Gpows = precompute());
|
|
1180
|
+
let p = I;
|
|
1181
|
+
let f = G;
|
|
1182
|
+
const pow_2_w = 2 ** W;
|
|
1183
|
+
const maxNum = pow_2_w;
|
|
1184
|
+
const mask = big(pow_2_w - 1);
|
|
1185
|
+
const shiftBy = big(W);
|
|
1186
|
+
for (let w = 0; w < pwindows; w++) {
|
|
1187
|
+
let wbits = Number(n & mask);
|
|
1188
|
+
n >>= shiftBy;
|
|
1189
|
+
if (wbits > pwindowSize) {
|
|
1190
|
+
wbits -= maxNum;
|
|
1191
|
+
n += 1n;
|
|
1192
|
+
}
|
|
1193
|
+
const off = w * pwindowSize;
|
|
1194
|
+
const offF = off;
|
|
1195
|
+
const offP = off + Math.abs(wbits) - 1;
|
|
1196
|
+
const isEven = w % 2 !== 0;
|
|
1197
|
+
const isNeg = wbits < 0;
|
|
1198
|
+
if (wbits === 0) {
|
|
1199
|
+
f = f.add(ctneg(isEven, comp[offF]));
|
|
1200
|
+
} else {
|
|
1201
|
+
p = p.add(ctneg(isNeg, comp[offP]));
|
|
1202
|
+
}
|
|
1203
|
+
}
|
|
1204
|
+
if (n !== 0n)
|
|
1205
|
+
err("invalid wnaf");
|
|
1206
|
+
return { p, f };
|
|
1207
|
+
};
|
|
1208
|
+
|
|
1209
|
+
// node_modules/@noble/hashes/esm/utils.js
|
|
1210
|
+
function isBytes2(a) {
|
|
1211
|
+
return a instanceof Uint8Array || ArrayBuffer.isView(a) && a.constructor.name === "Uint8Array";
|
|
1212
|
+
}
|
|
1213
|
+
function abytes2(b, ...lengths) {
|
|
1214
|
+
if (!isBytes2(b))
|
|
1215
|
+
throw new Error("Uint8Array expected");
|
|
1216
|
+
if (lengths.length > 0 && !lengths.includes(b.length))
|
|
1217
|
+
throw new Error("Uint8Array expected of length " + lengths + ", got length=" + b.length);
|
|
1218
|
+
}
|
|
1219
|
+
function aexists(instance, checkFinished = true) {
|
|
1220
|
+
if (instance.destroyed)
|
|
1221
|
+
throw new Error("Hash instance has been destroyed");
|
|
1222
|
+
if (checkFinished && instance.finished)
|
|
1223
|
+
throw new Error("Hash#digest() has already been called");
|
|
1224
|
+
}
|
|
1225
|
+
function aoutput(out, instance) {
|
|
1226
|
+
abytes2(out);
|
|
1227
|
+
const min = instance.outputLen;
|
|
1228
|
+
if (out.length < min) {
|
|
1229
|
+
throw new Error("digestInto() expects output buffer of length at least " + min);
|
|
1230
|
+
}
|
|
1231
|
+
}
|
|
1232
|
+
function clean(...arrays) {
|
|
1233
|
+
for (let i = 0; i < arrays.length; i++) {
|
|
1234
|
+
arrays[i].fill(0);
|
|
1235
|
+
}
|
|
1236
|
+
}
|
|
1237
|
+
function createView(arr) {
|
|
1238
|
+
return new DataView(arr.buffer, arr.byteOffset, arr.byteLength);
|
|
1239
|
+
}
|
|
1240
|
+
function utf8ToBytes(str) {
|
|
1241
|
+
if (typeof str !== "string")
|
|
1242
|
+
throw new Error("string expected");
|
|
1243
|
+
return new Uint8Array(new TextEncoder().encode(str));
|
|
1244
|
+
}
|
|
1245
|
+
function toBytes(data) {
|
|
1246
|
+
if (typeof data === "string")
|
|
1247
|
+
data = utf8ToBytes(data);
|
|
1248
|
+
abytes2(data);
|
|
1249
|
+
return data;
|
|
1250
|
+
}
|
|
1251
|
+
var Hash = class {
|
|
1252
|
+
};
|
|
1253
|
+
function createHasher(hashCons) {
|
|
1254
|
+
const hashC = (msg) => hashCons().update(toBytes(msg)).digest();
|
|
1255
|
+
const tmp = hashCons();
|
|
1256
|
+
hashC.outputLen = tmp.outputLen;
|
|
1257
|
+
hashC.blockLen = tmp.blockLen;
|
|
1258
|
+
hashC.create = () => hashCons();
|
|
1259
|
+
return hashC;
|
|
1260
|
+
}
|
|
1261
|
+
|
|
1262
|
+
// node_modules/@noble/hashes/esm/_md.js
|
|
1263
|
+
function setBigUint64(view, byteOffset, value, isLE) {
|
|
1264
|
+
if (typeof view.setBigUint64 === "function")
|
|
1265
|
+
return view.setBigUint64(byteOffset, value, isLE);
|
|
1266
|
+
const _32n2 = BigInt(32);
|
|
1267
|
+
const _u32_max = BigInt(4294967295);
|
|
1268
|
+
const wh = Number(value >> _32n2 & _u32_max);
|
|
1269
|
+
const wl = Number(value & _u32_max);
|
|
1270
|
+
const h2 = isLE ? 4 : 0;
|
|
1271
|
+
const l = isLE ? 0 : 4;
|
|
1272
|
+
view.setUint32(byteOffset + h2, wh, isLE);
|
|
1273
|
+
view.setUint32(byteOffset + l, wl, isLE);
|
|
1274
|
+
}
|
|
1275
|
+
var HashMD = class extends Hash {
|
|
1276
|
+
constructor(blockLen, outputLen, padOffset, isLE) {
|
|
1277
|
+
super();
|
|
1278
|
+
this.finished = false;
|
|
1279
|
+
this.length = 0;
|
|
1280
|
+
this.pos = 0;
|
|
1281
|
+
this.destroyed = false;
|
|
1282
|
+
this.blockLen = blockLen;
|
|
1283
|
+
this.outputLen = outputLen;
|
|
1284
|
+
this.padOffset = padOffset;
|
|
1285
|
+
this.isLE = isLE;
|
|
1286
|
+
this.buffer = new Uint8Array(blockLen);
|
|
1287
|
+
this.view = createView(this.buffer);
|
|
1288
|
+
}
|
|
1289
|
+
update(data) {
|
|
1290
|
+
aexists(this);
|
|
1291
|
+
data = toBytes(data);
|
|
1292
|
+
abytes2(data);
|
|
1293
|
+
const { view, buffer, blockLen } = this;
|
|
1294
|
+
const len = data.length;
|
|
1295
|
+
for (let pos = 0; pos < len; ) {
|
|
1296
|
+
const take = Math.min(blockLen - this.pos, len - pos);
|
|
1297
|
+
if (take === blockLen) {
|
|
1298
|
+
const dataView = createView(data);
|
|
1299
|
+
for (; blockLen <= len - pos; pos += blockLen)
|
|
1300
|
+
this.process(dataView, pos);
|
|
1301
|
+
continue;
|
|
1302
|
+
}
|
|
1303
|
+
buffer.set(data.subarray(pos, pos + take), this.pos);
|
|
1304
|
+
this.pos += take;
|
|
1305
|
+
pos += take;
|
|
1306
|
+
if (this.pos === blockLen) {
|
|
1307
|
+
this.process(view, 0);
|
|
1308
|
+
this.pos = 0;
|
|
1309
|
+
}
|
|
1310
|
+
}
|
|
1311
|
+
this.length += data.length;
|
|
1312
|
+
this.roundClean();
|
|
1313
|
+
return this;
|
|
1314
|
+
}
|
|
1315
|
+
digestInto(out) {
|
|
1316
|
+
aexists(this);
|
|
1317
|
+
aoutput(out, this);
|
|
1318
|
+
this.finished = true;
|
|
1319
|
+
const { buffer, view, blockLen, isLE } = this;
|
|
1320
|
+
let { pos } = this;
|
|
1321
|
+
buffer[pos++] = 128;
|
|
1322
|
+
clean(this.buffer.subarray(pos));
|
|
1323
|
+
if (this.padOffset > blockLen - pos) {
|
|
1324
|
+
this.process(view, 0);
|
|
1325
|
+
pos = 0;
|
|
1326
|
+
}
|
|
1327
|
+
for (let i = pos; i < blockLen; i++)
|
|
1328
|
+
buffer[i] = 0;
|
|
1329
|
+
setBigUint64(view, blockLen - 8, BigInt(this.length * 8), isLE);
|
|
1330
|
+
this.process(view, 0);
|
|
1331
|
+
const oview = createView(out);
|
|
1332
|
+
const len = this.outputLen;
|
|
1333
|
+
if (len % 4)
|
|
1334
|
+
throw new Error("_sha2: outputLen should be aligned to 32bit");
|
|
1335
|
+
const outLen = len / 4;
|
|
1336
|
+
const state = this.get();
|
|
1337
|
+
if (outLen > state.length)
|
|
1338
|
+
throw new Error("_sha2: outputLen bigger than state");
|
|
1339
|
+
for (let i = 0; i < outLen; i++)
|
|
1340
|
+
oview.setUint32(4 * i, state[i], isLE);
|
|
1341
|
+
}
|
|
1342
|
+
digest() {
|
|
1343
|
+
const { buffer, outputLen } = this;
|
|
1344
|
+
this.digestInto(buffer);
|
|
1345
|
+
const res = buffer.slice(0, outputLen);
|
|
1346
|
+
this.destroy();
|
|
1347
|
+
return res;
|
|
1348
|
+
}
|
|
1349
|
+
_cloneInto(to) {
|
|
1350
|
+
to || (to = new this.constructor());
|
|
1351
|
+
to.set(...this.get());
|
|
1352
|
+
const { blockLen, buffer, length, finished, destroyed, pos } = this;
|
|
1353
|
+
to.destroyed = destroyed;
|
|
1354
|
+
to.finished = finished;
|
|
1355
|
+
to.length = length;
|
|
1356
|
+
to.pos = pos;
|
|
1357
|
+
if (length % blockLen)
|
|
1358
|
+
to.buffer.set(buffer);
|
|
1359
|
+
return to;
|
|
1360
|
+
}
|
|
1361
|
+
clone() {
|
|
1362
|
+
return this._cloneInto();
|
|
1363
|
+
}
|
|
1364
|
+
};
|
|
1365
|
+
var SHA512_IV = /* @__PURE__ */ Uint32Array.from([
|
|
1366
|
+
1779033703,
|
|
1367
|
+
4089235720,
|
|
1368
|
+
3144134277,
|
|
1369
|
+
2227873595,
|
|
1370
|
+
1013904242,
|
|
1371
|
+
4271175723,
|
|
1372
|
+
2773480762,
|
|
1373
|
+
1595750129,
|
|
1374
|
+
1359893119,
|
|
1375
|
+
2917565137,
|
|
1376
|
+
2600822924,
|
|
1377
|
+
725511199,
|
|
1378
|
+
528734635,
|
|
1379
|
+
4215389547,
|
|
1380
|
+
1541459225,
|
|
1381
|
+
327033209
|
|
1382
|
+
]);
|
|
1383
|
+
|
|
1384
|
+
// node_modules/@noble/hashes/esm/_u64.js
|
|
1385
|
+
var U32_MASK64 = /* @__PURE__ */ BigInt(2 ** 32 - 1);
|
|
1386
|
+
var _32n = /* @__PURE__ */ BigInt(32);
|
|
1387
|
+
function fromBig(n, le = false) {
|
|
1388
|
+
if (le)
|
|
1389
|
+
return { h: Number(n & U32_MASK64), l: Number(n >> _32n & U32_MASK64) };
|
|
1390
|
+
return { h: Number(n >> _32n & U32_MASK64) | 0, l: Number(n & U32_MASK64) | 0 };
|
|
1391
|
+
}
|
|
1392
|
+
function split(lst, le = false) {
|
|
1393
|
+
const len = lst.length;
|
|
1394
|
+
let Ah = new Uint32Array(len);
|
|
1395
|
+
let Al = new Uint32Array(len);
|
|
1396
|
+
for (let i = 0; i < len; i++) {
|
|
1397
|
+
const { h: h2, l } = fromBig(lst[i], le);
|
|
1398
|
+
[Ah[i], Al[i]] = [h2, l];
|
|
1399
|
+
}
|
|
1400
|
+
return [Ah, Al];
|
|
1401
|
+
}
|
|
1402
|
+
var shrSH = (h2, _l, s) => h2 >>> s;
|
|
1403
|
+
var shrSL = (h2, l, s) => h2 << 32 - s | l >>> s;
|
|
1404
|
+
var rotrSH = (h2, l, s) => h2 >>> s | l << 32 - s;
|
|
1405
|
+
var rotrSL = (h2, l, s) => h2 << 32 - s | l >>> s;
|
|
1406
|
+
var rotrBH = (h2, l, s) => h2 << 64 - s | l >>> s - 32;
|
|
1407
|
+
var rotrBL = (h2, l, s) => h2 >>> s - 32 | l << 64 - s;
|
|
1408
|
+
function add(Ah, Al, Bh, Bl) {
|
|
1409
|
+
const l = (Al >>> 0) + (Bl >>> 0);
|
|
1410
|
+
return { h: Ah + Bh + (l / 2 ** 32 | 0) | 0, l: l | 0 };
|
|
1411
|
+
}
|
|
1412
|
+
var add3L = (Al, Bl, Cl) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0);
|
|
1413
|
+
var add3H = (low, Ah, Bh, Ch) => Ah + Bh + Ch + (low / 2 ** 32 | 0) | 0;
|
|
1414
|
+
var add4L = (Al, Bl, Cl, Dl) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0) + (Dl >>> 0);
|
|
1415
|
+
var add4H = (low, Ah, Bh, Ch, Dh) => Ah + Bh + Ch + Dh + (low / 2 ** 32 | 0) | 0;
|
|
1416
|
+
var add5L = (Al, Bl, Cl, Dl, El) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0) + (Dl >>> 0) + (El >>> 0);
|
|
1417
|
+
var add5H = (low, Ah, Bh, Ch, Dh, Eh) => Ah + Bh + Ch + Dh + Eh + (low / 2 ** 32 | 0) | 0;
|
|
1418
|
+
|
|
1419
|
+
// node_modules/@noble/hashes/esm/sha2.js
|
|
1420
|
+
var K512 = /* @__PURE__ */ (() => split([
|
|
1421
|
+
"0x428a2f98d728ae22",
|
|
1422
|
+
"0x7137449123ef65cd",
|
|
1423
|
+
"0xb5c0fbcfec4d3b2f",
|
|
1424
|
+
"0xe9b5dba58189dbbc",
|
|
1425
|
+
"0x3956c25bf348b538",
|
|
1426
|
+
"0x59f111f1b605d019",
|
|
1427
|
+
"0x923f82a4af194f9b",
|
|
1428
|
+
"0xab1c5ed5da6d8118",
|
|
1429
|
+
"0xd807aa98a3030242",
|
|
1430
|
+
"0x12835b0145706fbe",
|
|
1431
|
+
"0x243185be4ee4b28c",
|
|
1432
|
+
"0x550c7dc3d5ffb4e2",
|
|
1433
|
+
"0x72be5d74f27b896f",
|
|
1434
|
+
"0x80deb1fe3b1696b1",
|
|
1435
|
+
"0x9bdc06a725c71235",
|
|
1436
|
+
"0xc19bf174cf692694",
|
|
1437
|
+
"0xe49b69c19ef14ad2",
|
|
1438
|
+
"0xefbe4786384f25e3",
|
|
1439
|
+
"0x0fc19dc68b8cd5b5",
|
|
1440
|
+
"0x240ca1cc77ac9c65",
|
|
1441
|
+
"0x2de92c6f592b0275",
|
|
1442
|
+
"0x4a7484aa6ea6e483",
|
|
1443
|
+
"0x5cb0a9dcbd41fbd4",
|
|
1444
|
+
"0x76f988da831153b5",
|
|
1445
|
+
"0x983e5152ee66dfab",
|
|
1446
|
+
"0xa831c66d2db43210",
|
|
1447
|
+
"0xb00327c898fb213f",
|
|
1448
|
+
"0xbf597fc7beef0ee4",
|
|
1449
|
+
"0xc6e00bf33da88fc2",
|
|
1450
|
+
"0xd5a79147930aa725",
|
|
1451
|
+
"0x06ca6351e003826f",
|
|
1452
|
+
"0x142929670a0e6e70",
|
|
1453
|
+
"0x27b70a8546d22ffc",
|
|
1454
|
+
"0x2e1b21385c26c926",
|
|
1455
|
+
"0x4d2c6dfc5ac42aed",
|
|
1456
|
+
"0x53380d139d95b3df",
|
|
1457
|
+
"0x650a73548baf63de",
|
|
1458
|
+
"0x766a0abb3c77b2a8",
|
|
1459
|
+
"0x81c2c92e47edaee6",
|
|
1460
|
+
"0x92722c851482353b",
|
|
1461
|
+
"0xa2bfe8a14cf10364",
|
|
1462
|
+
"0xa81a664bbc423001",
|
|
1463
|
+
"0xc24b8b70d0f89791",
|
|
1464
|
+
"0xc76c51a30654be30",
|
|
1465
|
+
"0xd192e819d6ef5218",
|
|
1466
|
+
"0xd69906245565a910",
|
|
1467
|
+
"0xf40e35855771202a",
|
|
1468
|
+
"0x106aa07032bbd1b8",
|
|
1469
|
+
"0x19a4c116b8d2d0c8",
|
|
1470
|
+
"0x1e376c085141ab53",
|
|
1471
|
+
"0x2748774cdf8eeb99",
|
|
1472
|
+
"0x34b0bcb5e19b48a8",
|
|
1473
|
+
"0x391c0cb3c5c95a63",
|
|
1474
|
+
"0x4ed8aa4ae3418acb",
|
|
1475
|
+
"0x5b9cca4f7763e373",
|
|
1476
|
+
"0x682e6ff3d6b2b8a3",
|
|
1477
|
+
"0x748f82ee5defb2fc",
|
|
1478
|
+
"0x78a5636f43172f60",
|
|
1479
|
+
"0x84c87814a1f0ab72",
|
|
1480
|
+
"0x8cc702081a6439ec",
|
|
1481
|
+
"0x90befffa23631e28",
|
|
1482
|
+
"0xa4506cebde82bde9",
|
|
1483
|
+
"0xbef9a3f7b2c67915",
|
|
1484
|
+
"0xc67178f2e372532b",
|
|
1485
|
+
"0xca273eceea26619c",
|
|
1486
|
+
"0xd186b8c721c0c207",
|
|
1487
|
+
"0xeada7dd6cde0eb1e",
|
|
1488
|
+
"0xf57d4f7fee6ed178",
|
|
1489
|
+
"0x06f067aa72176fba",
|
|
1490
|
+
"0x0a637dc5a2c898a6",
|
|
1491
|
+
"0x113f9804bef90dae",
|
|
1492
|
+
"0x1b710b35131c471b",
|
|
1493
|
+
"0x28db77f523047d84",
|
|
1494
|
+
"0x32caab7b40c72493",
|
|
1495
|
+
"0x3c9ebe0a15c9bebc",
|
|
1496
|
+
"0x431d67c49c100d4c",
|
|
1497
|
+
"0x4cc5d4becb3e42b6",
|
|
1498
|
+
"0x597f299cfc657e2a",
|
|
1499
|
+
"0x5fcb6fab3ad6faec",
|
|
1500
|
+
"0x6c44198c4a475817"
|
|
1501
|
+
].map((n) => BigInt(n))))();
|
|
1502
|
+
var SHA512_Kh = /* @__PURE__ */ (() => K512[0])();
|
|
1503
|
+
var SHA512_Kl = /* @__PURE__ */ (() => K512[1])();
|
|
1504
|
+
var SHA512_W_H = /* @__PURE__ */ new Uint32Array(80);
|
|
1505
|
+
var SHA512_W_L = /* @__PURE__ */ new Uint32Array(80);
|
|
1506
|
+
var SHA512 = class extends HashMD {
|
|
1507
|
+
constructor(outputLen = 64) {
|
|
1508
|
+
super(128, outputLen, 16, false);
|
|
1509
|
+
this.Ah = SHA512_IV[0] | 0;
|
|
1510
|
+
this.Al = SHA512_IV[1] | 0;
|
|
1511
|
+
this.Bh = SHA512_IV[2] | 0;
|
|
1512
|
+
this.Bl = SHA512_IV[3] | 0;
|
|
1513
|
+
this.Ch = SHA512_IV[4] | 0;
|
|
1514
|
+
this.Cl = SHA512_IV[5] | 0;
|
|
1515
|
+
this.Dh = SHA512_IV[6] | 0;
|
|
1516
|
+
this.Dl = SHA512_IV[7] | 0;
|
|
1517
|
+
this.Eh = SHA512_IV[8] | 0;
|
|
1518
|
+
this.El = SHA512_IV[9] | 0;
|
|
1519
|
+
this.Fh = SHA512_IV[10] | 0;
|
|
1520
|
+
this.Fl = SHA512_IV[11] | 0;
|
|
1521
|
+
this.Gh = SHA512_IV[12] | 0;
|
|
1522
|
+
this.Gl = SHA512_IV[13] | 0;
|
|
1523
|
+
this.Hh = SHA512_IV[14] | 0;
|
|
1524
|
+
this.Hl = SHA512_IV[15] | 0;
|
|
1525
|
+
}
|
|
1526
|
+
// prettier-ignore
|
|
1527
|
+
get() {
|
|
1528
|
+
const { Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl } = this;
|
|
1529
|
+
return [Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl];
|
|
1530
|
+
}
|
|
1531
|
+
// prettier-ignore
|
|
1532
|
+
set(Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl) {
|
|
1533
|
+
this.Ah = Ah | 0;
|
|
1534
|
+
this.Al = Al | 0;
|
|
1535
|
+
this.Bh = Bh | 0;
|
|
1536
|
+
this.Bl = Bl | 0;
|
|
1537
|
+
this.Ch = Ch | 0;
|
|
1538
|
+
this.Cl = Cl | 0;
|
|
1539
|
+
this.Dh = Dh | 0;
|
|
1540
|
+
this.Dl = Dl | 0;
|
|
1541
|
+
this.Eh = Eh | 0;
|
|
1542
|
+
this.El = El | 0;
|
|
1543
|
+
this.Fh = Fh | 0;
|
|
1544
|
+
this.Fl = Fl | 0;
|
|
1545
|
+
this.Gh = Gh | 0;
|
|
1546
|
+
this.Gl = Gl | 0;
|
|
1547
|
+
this.Hh = Hh | 0;
|
|
1548
|
+
this.Hl = Hl | 0;
|
|
1549
|
+
}
|
|
1550
|
+
process(view, offset) {
|
|
1551
|
+
for (let i = 0; i < 16; i++, offset += 4) {
|
|
1552
|
+
SHA512_W_H[i] = view.getUint32(offset);
|
|
1553
|
+
SHA512_W_L[i] = view.getUint32(offset += 4);
|
|
1554
|
+
}
|
|
1555
|
+
for (let i = 16; i < 80; i++) {
|
|
1556
|
+
const W15h = SHA512_W_H[i - 15] | 0;
|
|
1557
|
+
const W15l = SHA512_W_L[i - 15] | 0;
|
|
1558
|
+
const s0h = rotrSH(W15h, W15l, 1) ^ rotrSH(W15h, W15l, 8) ^ shrSH(W15h, W15l, 7);
|
|
1559
|
+
const s0l = rotrSL(W15h, W15l, 1) ^ rotrSL(W15h, W15l, 8) ^ shrSL(W15h, W15l, 7);
|
|
1560
|
+
const W2h = SHA512_W_H[i - 2] | 0;
|
|
1561
|
+
const W2l = SHA512_W_L[i - 2] | 0;
|
|
1562
|
+
const s1h = rotrSH(W2h, W2l, 19) ^ rotrBH(W2h, W2l, 61) ^ shrSH(W2h, W2l, 6);
|
|
1563
|
+
const s1l = rotrSL(W2h, W2l, 19) ^ rotrBL(W2h, W2l, 61) ^ shrSL(W2h, W2l, 6);
|
|
1564
|
+
const SUMl = add4L(s0l, s1l, SHA512_W_L[i - 7], SHA512_W_L[i - 16]);
|
|
1565
|
+
const SUMh = add4H(SUMl, s0h, s1h, SHA512_W_H[i - 7], SHA512_W_H[i - 16]);
|
|
1566
|
+
SHA512_W_H[i] = SUMh | 0;
|
|
1567
|
+
SHA512_W_L[i] = SUMl | 0;
|
|
1568
|
+
}
|
|
1569
|
+
let { Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl } = this;
|
|
1570
|
+
for (let i = 0; i < 80; i++) {
|
|
1571
|
+
const sigma1h = rotrSH(Eh, El, 14) ^ rotrSH(Eh, El, 18) ^ rotrBH(Eh, El, 41);
|
|
1572
|
+
const sigma1l = rotrSL(Eh, El, 14) ^ rotrSL(Eh, El, 18) ^ rotrBL(Eh, El, 41);
|
|
1573
|
+
const CHIh = Eh & Fh ^ ~Eh & Gh;
|
|
1574
|
+
const CHIl = El & Fl ^ ~El & Gl;
|
|
1575
|
+
const T1ll = add5L(Hl, sigma1l, CHIl, SHA512_Kl[i], SHA512_W_L[i]);
|
|
1576
|
+
const T1h = add5H(T1ll, Hh, sigma1h, CHIh, SHA512_Kh[i], SHA512_W_H[i]);
|
|
1577
|
+
const T1l = T1ll | 0;
|
|
1578
|
+
const sigma0h = rotrSH(Ah, Al, 28) ^ rotrBH(Ah, Al, 34) ^ rotrBH(Ah, Al, 39);
|
|
1579
|
+
const sigma0l = rotrSL(Ah, Al, 28) ^ rotrBL(Ah, Al, 34) ^ rotrBL(Ah, Al, 39);
|
|
1580
|
+
const MAJh = Ah & Bh ^ Ah & Ch ^ Bh & Ch;
|
|
1581
|
+
const MAJl = Al & Bl ^ Al & Cl ^ Bl & Cl;
|
|
1582
|
+
Hh = Gh | 0;
|
|
1583
|
+
Hl = Gl | 0;
|
|
1584
|
+
Gh = Fh | 0;
|
|
1585
|
+
Gl = Fl | 0;
|
|
1586
|
+
Fh = Eh | 0;
|
|
1587
|
+
Fl = El | 0;
|
|
1588
|
+
({ h: Eh, l: El } = add(Dh | 0, Dl | 0, T1h | 0, T1l | 0));
|
|
1589
|
+
Dh = Ch | 0;
|
|
1590
|
+
Dl = Cl | 0;
|
|
1591
|
+
Ch = Bh | 0;
|
|
1592
|
+
Cl = Bl | 0;
|
|
1593
|
+
Bh = Ah | 0;
|
|
1594
|
+
Bl = Al | 0;
|
|
1595
|
+
const All = add3L(T1l, sigma0l, MAJl);
|
|
1596
|
+
Ah = add3H(All, T1h, sigma0h, MAJh);
|
|
1597
|
+
Al = All | 0;
|
|
1598
|
+
}
|
|
1599
|
+
({ h: Ah, l: Al } = add(this.Ah | 0, this.Al | 0, Ah | 0, Al | 0));
|
|
1600
|
+
({ h: Bh, l: Bl } = add(this.Bh | 0, this.Bl | 0, Bh | 0, Bl | 0));
|
|
1601
|
+
({ h: Ch, l: Cl } = add(this.Ch | 0, this.Cl | 0, Ch | 0, Cl | 0));
|
|
1602
|
+
({ h: Dh, l: Dl } = add(this.Dh | 0, this.Dl | 0, Dh | 0, Dl | 0));
|
|
1603
|
+
({ h: Eh, l: El } = add(this.Eh | 0, this.El | 0, Eh | 0, El | 0));
|
|
1604
|
+
({ h: Fh, l: Fl } = add(this.Fh | 0, this.Fl | 0, Fh | 0, Fl | 0));
|
|
1605
|
+
({ h: Gh, l: Gl } = add(this.Gh | 0, this.Gl | 0, Gh | 0, Gl | 0));
|
|
1606
|
+
({ h: Hh, l: Hl } = add(this.Hh | 0, this.Hl | 0, Hh | 0, Hl | 0));
|
|
1607
|
+
this.set(Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl);
|
|
1608
|
+
}
|
|
1609
|
+
roundClean() {
|
|
1610
|
+
clean(SHA512_W_H, SHA512_W_L);
|
|
1611
|
+
}
|
|
1612
|
+
destroy() {
|
|
1613
|
+
clean(this.buffer);
|
|
1614
|
+
this.set(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
|
|
1615
|
+
}
|
|
1616
|
+
};
|
|
1617
|
+
var sha512 = /* @__PURE__ */ createHasher(() => new SHA512());
|
|
1618
|
+
|
|
1619
|
+
// src/nodeReceipt.ts
|
|
1620
|
+
hashes.sha512 = sha512;
|
|
1621
|
+
function base64urlToBytes(s) {
|
|
1622
|
+
const pad = s.length % 4;
|
|
1623
|
+
const base64 = s.replace(/-/g, "+").replace(/_/g, "/") + (pad ? "=".repeat(4 - pad) : "");
|
|
1624
|
+
if (typeof Buffer !== "undefined") {
|
|
1625
|
+
return new Uint8Array(Buffer.from(base64, "base64"));
|
|
1626
|
+
}
|
|
1627
|
+
const binary = atob(base64);
|
|
1628
|
+
return Uint8Array.from(binary, (c) => c.charCodeAt(0));
|
|
1629
|
+
}
|
|
1630
|
+
async function verifyNodeReceiptSignature(params) {
|
|
1631
|
+
try {
|
|
1632
|
+
const { receipt, signatureB64Url, key } = params;
|
|
1633
|
+
let pubKeyBytes;
|
|
1634
|
+
if (key.jwk) {
|
|
1635
|
+
if (key.jwk.kty !== "OKP" || key.jwk.crv !== "Ed25519") {
|
|
1636
|
+
return {
|
|
1637
|
+
ok: false,
|
|
1638
|
+
code: CerVerifyCode.ATTESTATION_KEY_FORMAT_UNSUPPORTED,
|
|
1639
|
+
details: [
|
|
1640
|
+
`JWK must have kty=OKP and crv=Ed25519, got kty=${key.jwk.kty} crv=${key.jwk.crv}`
|
|
1641
|
+
]
|
|
1642
|
+
};
|
|
1643
|
+
}
|
|
1644
|
+
pubKeyBytes = base64urlToBytes(key.jwk.x);
|
|
1645
|
+
} else if (key.rawB64Url) {
|
|
1646
|
+
pubKeyBytes = base64urlToBytes(key.rawB64Url);
|
|
1647
|
+
} else if (key.spkiB64) {
|
|
1648
|
+
const spkiBytes = base64urlToBytes(key.spkiB64);
|
|
1649
|
+
if (spkiBytes.length < 32) {
|
|
1650
|
+
return {
|
|
1651
|
+
ok: false,
|
|
1652
|
+
code: CerVerifyCode.ATTESTATION_KEY_FORMAT_UNSUPPORTED,
|
|
1653
|
+
details: ["SPKI key too short to extract Ed25519 public key"]
|
|
1654
|
+
};
|
|
1655
|
+
}
|
|
1656
|
+
pubKeyBytes = spkiBytes.slice(spkiBytes.length - 32);
|
|
1657
|
+
} else {
|
|
1658
|
+
return {
|
|
1659
|
+
ok: false,
|
|
1660
|
+
code: CerVerifyCode.ATTESTATION_KEY_FORMAT_UNSUPPORTED,
|
|
1661
|
+
details: ["No usable key provided: supply jwk, rawB64Url, or spkiB64"]
|
|
1662
|
+
};
|
|
1663
|
+
}
|
|
1664
|
+
if (pubKeyBytes.length !== 32) {
|
|
1665
|
+
return {
|
|
1666
|
+
ok: false,
|
|
1667
|
+
code: CerVerifyCode.ATTESTATION_KEY_FORMAT_UNSUPPORTED,
|
|
1668
|
+
details: [`Ed25519 public key must be 32 bytes, got ${pubKeyBytes.length}`]
|
|
1669
|
+
};
|
|
1670
|
+
}
|
|
1671
|
+
const sigBytes = base64urlToBytes(signatureB64Url);
|
|
1672
|
+
if (sigBytes.length !== 64) {
|
|
1673
|
+
return {
|
|
1674
|
+
ok: false,
|
|
1675
|
+
code: CerVerifyCode.ATTESTATION_INVALID_SIGNATURE,
|
|
1676
|
+
details: [`Ed25519 signature must be 64 bytes, got ${sigBytes.length}`]
|
|
1677
|
+
};
|
|
1678
|
+
}
|
|
1679
|
+
const msgBytes = new TextEncoder().encode(toCanonicalJson(receipt));
|
|
1680
|
+
const isValid = await verify(sigBytes, msgBytes, pubKeyBytes);
|
|
1681
|
+
if (!isValid) {
|
|
1682
|
+
return {
|
|
1683
|
+
ok: false,
|
|
1684
|
+
code: CerVerifyCode.ATTESTATION_INVALID_SIGNATURE,
|
|
1685
|
+
details: ["Ed25519 signature verification failed"]
|
|
1686
|
+
};
|
|
1687
|
+
}
|
|
1688
|
+
return { ok: true, code: CerVerifyCode.OK };
|
|
1689
|
+
} catch (err2) {
|
|
1690
|
+
return {
|
|
1691
|
+
ok: false,
|
|
1692
|
+
code: CerVerifyCode.ATTESTATION_INVALID_SIGNATURE,
|
|
1693
|
+
details: [err2 instanceof Error ? err2.message : String(err2)]
|
|
1694
|
+
};
|
|
1695
|
+
}
|
|
1696
|
+
}
|
|
1697
|
+
async function fetchNodeKeys(nodeUrl) {
|
|
1698
|
+
const url = `${nodeUrl.replace(/\/+$/, "")}/.well-known/nexart-node.json`;
|
|
1699
|
+
const response = await fetch(url);
|
|
1700
|
+
if (!response.ok) {
|
|
1701
|
+
throw new Error(`Failed to fetch node keys from ${url}: HTTP ${response.status}`);
|
|
1702
|
+
}
|
|
1703
|
+
const data = await response.json();
|
|
1704
|
+
if (typeof data !== "object" || data === null) {
|
|
1705
|
+
throw new Error("Node keys response is not an object");
|
|
1706
|
+
}
|
|
1707
|
+
const doc = data;
|
|
1708
|
+
if (typeof doc.nodeId !== "string" || !Array.isArray(doc.keys)) {
|
|
1709
|
+
throw new Error("Node keys document missing required fields (nodeId, keys)");
|
|
1710
|
+
}
|
|
1711
|
+
return data;
|
|
1712
|
+
}
|
|
1713
|
+
function selectNodeKey(doc, kid) {
|
|
1714
|
+
if (kid) {
|
|
1715
|
+
const found = doc.keys.find((k) => k.kid === kid);
|
|
1716
|
+
if (!found) {
|
|
1717
|
+
return {
|
|
1718
|
+
error: {
|
|
1719
|
+
ok: false,
|
|
1720
|
+
code: CerVerifyCode.ATTESTATION_KEY_NOT_FOUND,
|
|
1721
|
+
details: [`Key with kid="${kid}" not found in node keys document`]
|
|
1722
|
+
}
|
|
1723
|
+
};
|
|
1724
|
+
}
|
|
1725
|
+
return { key: found };
|
|
1726
|
+
}
|
|
1727
|
+
if (doc.activeKid) {
|
|
1728
|
+
const found = doc.keys.find((k) => k.kid === doc.activeKid);
|
|
1729
|
+
if (!found) {
|
|
1730
|
+
return {
|
|
1731
|
+
error: {
|
|
1732
|
+
ok: false,
|
|
1733
|
+
code: CerVerifyCode.ATTESTATION_KEY_NOT_FOUND,
|
|
1734
|
+
details: [`activeKid="${doc.activeKid}" not found in keys array`]
|
|
1735
|
+
}
|
|
1736
|
+
};
|
|
1737
|
+
}
|
|
1738
|
+
return { key: found };
|
|
1739
|
+
}
|
|
1740
|
+
if (doc.keys.length === 0) {
|
|
1741
|
+
return {
|
|
1742
|
+
error: {
|
|
1743
|
+
ok: false,
|
|
1744
|
+
code: CerVerifyCode.ATTESTATION_KEY_NOT_FOUND,
|
|
1745
|
+
details: ["No keys available in node keys document"]
|
|
1746
|
+
}
|
|
1747
|
+
};
|
|
1748
|
+
}
|
|
1749
|
+
return { key: doc.keys[0] };
|
|
1750
|
+
}
|
|
1751
|
+
function extractReceiptAndSignature(bundle) {
|
|
1752
|
+
if (typeof bundle !== "object" || bundle === null) return null;
|
|
1753
|
+
const b = bundle;
|
|
1754
|
+
if (typeof b.receipt === "object" && b.receipt !== null && typeof b.signature === "string") {
|
|
1755
|
+
return {
|
|
1756
|
+
receipt: b.receipt,
|
|
1757
|
+
signatureB64Url: b.signature,
|
|
1758
|
+
attestorKeyId: typeof b.attestorKeyId === "string" ? b.attestorKeyId : void 0
|
|
1759
|
+
};
|
|
1760
|
+
}
|
|
1761
|
+
if (typeof b.meta === "object" && b.meta !== null) {
|
|
1762
|
+
const meta = b.meta;
|
|
1763
|
+
if (typeof meta.attestation === "object" && meta.attestation !== null) {
|
|
1764
|
+
const att = meta.attestation;
|
|
1765
|
+
if (typeof att.receipt === "object" && att.receipt !== null && typeof att.signature === "string") {
|
|
1766
|
+
return {
|
|
1767
|
+
receipt: att.receipt,
|
|
1768
|
+
signatureB64Url: att.signature,
|
|
1769
|
+
attestorKeyId: typeof att.attestorKeyId === "string" ? att.attestorKeyId : void 0
|
|
1770
|
+
};
|
|
1771
|
+
}
|
|
1772
|
+
}
|
|
1773
|
+
}
|
|
1774
|
+
return null;
|
|
1775
|
+
}
|
|
1776
|
+
async function verifyBundleAttestation(bundle, options) {
|
|
1777
|
+
const extracted = extractReceiptAndSignature(bundle);
|
|
1778
|
+
if (!extracted) {
|
|
1779
|
+
return {
|
|
1780
|
+
ok: false,
|
|
1781
|
+
code: CerVerifyCode.ATTESTATION_MISSING,
|
|
1782
|
+
details: ["No signed receipt found in bundle (expected bundle.receipt + bundle.signature)"]
|
|
1783
|
+
};
|
|
1784
|
+
}
|
|
1785
|
+
const nodeId = extracted.receipt.nodeId;
|
|
1786
|
+
const resolvedKid = options.kid ?? extracted.attestorKeyId ?? extracted.receipt.attestorKeyId;
|
|
1787
|
+
function ctx() {
|
|
1788
|
+
const lines = [];
|
|
1789
|
+
if (nodeId) lines.push(`nodeId: ${nodeId}`);
|
|
1790
|
+
if (resolvedKid) lines.push(`kid: ${resolvedKid}`);
|
|
1791
|
+
return lines;
|
|
1792
|
+
}
|
|
1793
|
+
let keysDoc;
|
|
1794
|
+
try {
|
|
1795
|
+
keysDoc = await fetchNodeKeys(options.nodeUrl);
|
|
1796
|
+
} catch (err2) {
|
|
1797
|
+
return {
|
|
1798
|
+
ok: false,
|
|
1799
|
+
code: CerVerifyCode.ATTESTATION_KEY_NOT_FOUND,
|
|
1800
|
+
details: [...ctx(), err2 instanceof Error ? err2.message : String(err2)]
|
|
1801
|
+
};
|
|
1802
|
+
}
|
|
1803
|
+
if (typeof bundle.certificateHash === "string") {
|
|
1804
|
+
const bundleCertHash = bundle.certificateHash;
|
|
1805
|
+
if (extracted.receipt.certificateHash !== bundleCertHash) {
|
|
1806
|
+
return {
|
|
1807
|
+
ok: false,
|
|
1808
|
+
code: CerVerifyCode.CERTIFICATE_HASH_MISMATCH,
|
|
1809
|
+
details: [
|
|
1810
|
+
`Receipt certificateHash does not match bundle certificateHash`,
|
|
1811
|
+
`receipt.certificateHash: ${extracted.receipt.certificateHash}`,
|
|
1812
|
+
`bundle.certificateHash: ${bundleCertHash}`,
|
|
1813
|
+
...ctx()
|
|
1814
|
+
]
|
|
1815
|
+
};
|
|
1816
|
+
}
|
|
1817
|
+
}
|
|
1818
|
+
const selected = selectNodeKey(keysDoc, resolvedKid);
|
|
1819
|
+
if (selected.error) {
|
|
1820
|
+
return {
|
|
1821
|
+
...selected.error,
|
|
1822
|
+
details: [...ctx(), ...selected.error.details ?? []]
|
|
1823
|
+
};
|
|
1824
|
+
}
|
|
1825
|
+
const keyEntry = selected.key;
|
|
1826
|
+
const keyParam = {};
|
|
1827
|
+
if (keyEntry.publicKeyJwk) keyParam.jwk = keyEntry.publicKeyJwk;
|
|
1828
|
+
else if (keyEntry.publicKey) keyParam.rawB64Url = keyEntry.publicKey;
|
|
1829
|
+
else if (keyEntry.publicKeySpkiB64) keyParam.spkiB64 = keyEntry.publicKeySpkiB64;
|
|
1830
|
+
else {
|
|
1831
|
+
return {
|
|
1832
|
+
ok: false,
|
|
1833
|
+
code: CerVerifyCode.ATTESTATION_KEY_FORMAT_UNSUPPORTED,
|
|
1834
|
+
details: [
|
|
1835
|
+
`Key kid="${keyEntry.kid}" has no usable public key field (publicKeyJwk, publicKey, or publicKeySpkiB64)`,
|
|
1836
|
+
...ctx()
|
|
1837
|
+
]
|
|
1838
|
+
};
|
|
1839
|
+
}
|
|
1840
|
+
const sigResult = await verifyNodeReceiptSignature({
|
|
1841
|
+
receipt: extracted.receipt,
|
|
1842
|
+
signatureB64Url: extracted.signatureB64Url,
|
|
1843
|
+
key: keyParam
|
|
1844
|
+
});
|
|
1845
|
+
const contextLines = ctx();
|
|
1846
|
+
if (contextLines.length === 0) return sigResult;
|
|
1847
|
+
return sigResult.ok ? { ok: true, code: CerVerifyCode.OK, details: contextLines } : { ...sigResult, details: [...contextLines, ...sigResult.details ?? []] };
|
|
1848
|
+
}
|
|
746
1849
|
// Annotate the CommonJS export names for ESM import in node:
|
|
747
1850
|
0 && (module.exports = {
|
|
748
1851
|
CerAttestationError,
|
|
@@ -757,6 +1860,7 @@ async function attestIfNeeded(bundle, options) {
|
|
|
757
1860
|
computeOutputHash,
|
|
758
1861
|
createSnapshot,
|
|
759
1862
|
exportCer,
|
|
1863
|
+
fetchNodeKeys,
|
|
760
1864
|
getAttestationReceipt,
|
|
761
1865
|
hasAttestation,
|
|
762
1866
|
hashCanonicalJson,
|
|
@@ -764,11 +1868,22 @@ async function attestIfNeeded(bundle, options) {
|
|
|
764
1868
|
importCer,
|
|
765
1869
|
sanitizeForAttestation,
|
|
766
1870
|
sealCer,
|
|
1871
|
+
selectNodeKey,
|
|
767
1872
|
sha256Hex,
|
|
768
1873
|
toCanonicalJson,
|
|
769
1874
|
verify,
|
|
1875
|
+
verifyBundleAttestation,
|
|
770
1876
|
verifyCer,
|
|
1877
|
+
verifyNodeReceiptSignature,
|
|
771
1878
|
verifySnapshot,
|
|
772
1879
|
wrapProvider
|
|
773
1880
|
});
|
|
1881
|
+
/*! Bundled license information:
|
|
1882
|
+
|
|
1883
|
+
@noble/ed25519/index.js:
|
|
1884
|
+
(*! noble-ed25519 - MIT License (c) 2019 Paul Miller (paulmillr.com) *)
|
|
1885
|
+
|
|
1886
|
+
@noble/hashes/esm/utils.js:
|
|
1887
|
+
(*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
|
1888
|
+
*/
|
|
774
1889
|
//# sourceMappingURL=index.cjs.map
|