@hlos-ai/schemas 0.6.0 → 0.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/index.cjs +178 -13
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +389 -9
- package/dist/index.d.ts +389 -9
- package/dist/index.js +162 -13
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -54,7 +54,7 @@ import {
|
|
|
54
54
|
SETTLEMENT_AUTHORITY,
|
|
55
55
|
type CrossingSettledReceipt, CrossingSettledReceiptSchema,
|
|
56
56
|
|
|
57
|
-
//
|
|
57
|
+
// Privacy-Preserving Proofs
|
|
58
58
|
W_RPID_DOMAIN, W_TXCTX_DOMAIN,
|
|
59
59
|
type RPID, RPIDSchema,
|
|
60
60
|
type TransactionContext, TransactionContextSchema,
|
package/dist/index.cjs
CHANGED
|
@@ -64,7 +64,16 @@ __export(src_exports, {
|
|
|
64
64
|
KernelErrorCodeSchema: () => KernelErrorCodeSchema2,
|
|
65
65
|
KernelErrorSchema: () => KernelErrorSchema,
|
|
66
66
|
KernelOkSchema: () => KernelOkSchema,
|
|
67
|
+
LIABILITY_WAIVER_TERMS_TYPE_URI: () => LIABILITY_WAIVER_TERMS_TYPE_URI,
|
|
68
|
+
LIABILITY_WAIVER_TERMS_VERSION: () => LIABILITY_WAIVER_TERMS_VERSION,
|
|
67
69
|
LiabilityAttestationContentSchema: () => LiabilityAttestationContentSchema,
|
|
70
|
+
LiabilityDispositionSchema: () => LiabilityDispositionSchema,
|
|
71
|
+
LiabilityWaiverTermsConditionsSchema: () => LiabilityWaiverTermsConditionsSchema,
|
|
72
|
+
LiabilityWaiverTermsHashInputSchema: () => LiabilityWaiverTermsHashInputSchema,
|
|
73
|
+
LiabilityWaiverTermsPartiesSchema: () => LiabilityWaiverTermsPartiesSchema,
|
|
74
|
+
LiabilityWaiverTermsRefV0Schema: () => LiabilityWaiverTermsRefV0Schema,
|
|
75
|
+
LiabilityWaiverTermsScopeSchema: () => LiabilityWaiverTermsScopeSchema,
|
|
76
|
+
LiabilityWaiverTermsV0Schema: () => LiabilityWaiverTermsV0Schema,
|
|
68
77
|
LogInclusionProofSchema: () => LogInclusionProofSchema,
|
|
69
78
|
NA_ID_PREFIX: () => NA_ID_PREFIX,
|
|
70
79
|
NotarizeResponseSchema: () => NotarizeResponseSchema,
|
|
@@ -91,6 +100,10 @@ __export(src_exports, {
|
|
|
91
100
|
SRR_REJECTION_DOMAIN: () => SRR_REJECTION_DOMAIN,
|
|
92
101
|
SRR_SIGNATURE_ALGORITHM: () => SRR_SIGNATURE_ALGORITHM,
|
|
93
102
|
SRR_TYPE_URI: () => SRR_TYPE_URI,
|
|
103
|
+
SRR_V1_REJECTION_DOMAIN: () => SRR_V1_REJECTION_DOMAIN,
|
|
104
|
+
SRR_V1_SIGNATURE_ALGORITHM: () => SRR_V1_SIGNATURE_ALGORITHM,
|
|
105
|
+
SRR_V1_TYPE_URI: () => SRR_V1_TYPE_URI,
|
|
106
|
+
SRR_V1_VERSION: () => SRR_V1_VERSION,
|
|
94
107
|
SRR_VERSION: () => SRR_VERSION,
|
|
95
108
|
SURFACES: () => SURFACES,
|
|
96
109
|
SettlementAnchorContentSchema: () => SettlementAnchorContentSchema,
|
|
@@ -101,6 +114,7 @@ __export(src_exports, {
|
|
|
101
114
|
SignedReceiptV0LooseSchema: () => SignedReceiptV0LooseSchema,
|
|
102
115
|
SignedReceiptV0Schema: () => SignedReceiptV0Schema,
|
|
103
116
|
SignedRejectionReceiptV0Schema: () => SignedRejectionReceiptV0Schema,
|
|
117
|
+
SignedRejectionReceiptV1Schema: () => SignedRejectionReceiptV1Schema,
|
|
104
118
|
StackConnectionSchema: () => StackConnectionSchema,
|
|
105
119
|
StackProviderSchema: () => StackProviderSchema,
|
|
106
120
|
StackSchema: () => StackSchema,
|
|
@@ -118,6 +132,7 @@ __export(src_exports, {
|
|
|
118
132
|
base64urlToBytes: () => base64urlToBytes,
|
|
119
133
|
bytesToBase64url: () => bytesToBase64url,
|
|
120
134
|
computeContentHash: () => computeContentHash,
|
|
135
|
+
computeLiabilityWaiverTermsHash: () => computeLiabilityWaiverTermsHash,
|
|
121
136
|
computeReceiptHash: () => computeReceiptHash,
|
|
122
137
|
computeSrrDigest: () => computeSrrDigest,
|
|
123
138
|
computeSrrSigningPayload: () => computeSrrSigningPayload,
|
|
@@ -141,6 +156,7 @@ __export(src_exports, {
|
|
|
141
156
|
kernelError: () => kernelError,
|
|
142
157
|
kernelOk: () => kernelOk,
|
|
143
158
|
success: () => success,
|
|
159
|
+
toLiabilityWaiverTermsHashInput: () => toLiabilityWaiverTermsHashInput,
|
|
144
160
|
validateTimeWindow: () => validateTimeWindow,
|
|
145
161
|
verifyAAR: () => verifyAAR,
|
|
146
162
|
verifyDetachedEd25519: () => verifyDetachedEd25519,
|
|
@@ -1499,9 +1515,57 @@ var SignedRejectionReceiptV0Schema = import_zod15.z.object({
|
|
|
1499
1515
|
signature: Base64urlEd25519SigSchema
|
|
1500
1516
|
}).strict();
|
|
1501
1517
|
|
|
1502
|
-
// src/
|
|
1503
|
-
var
|
|
1504
|
-
var
|
|
1518
|
+
// src/liability-waiver-terms-v0.ts
|
|
1519
|
+
var import_zod16 = require("zod");
|
|
1520
|
+
var LIABILITY_WAIVER_TERMS_TYPE_URI = "https://hlos.ai/schema/LiabilityWaiverTermsV0";
|
|
1521
|
+
var LIABILITY_WAIVER_TERMS_VERSION = 0;
|
|
1522
|
+
var LiabilityDispositionSchema = import_zod16.z.enum([
|
|
1523
|
+
"ABSORB",
|
|
1524
|
+
"RELEASE",
|
|
1525
|
+
"TRANSFER",
|
|
1526
|
+
"DISPUTE"
|
|
1527
|
+
]);
|
|
1528
|
+
var LiabilityWaiverTermsPartiesSchema = import_zod16.z.object({
|
|
1529
|
+
offered_by: import_zod16.z.string().min(1).optional(),
|
|
1530
|
+
offered_to: import_zod16.z.string().min(1).optional(),
|
|
1531
|
+
beneficiary: import_zod16.z.string().min(1).optional(),
|
|
1532
|
+
burdened_party: import_zod16.z.string().min(1).optional()
|
|
1533
|
+
}).strict();
|
|
1534
|
+
var LiabilityWaiverTermsScopeSchema = import_zod16.z.object({
|
|
1535
|
+
crossing_id: import_zod16.z.string().min(1).optional(),
|
|
1536
|
+
commitment_hash: Base64urlSha256Schema.optional(),
|
|
1537
|
+
claim_scope: import_zod16.z.string().min(1).optional()
|
|
1538
|
+
}).strict();
|
|
1539
|
+
var LiabilityWaiverTermsConditionsSchema = import_zod16.z.object({
|
|
1540
|
+
effective_if: import_zod16.z.record(import_zod16.z.unknown()).optional(),
|
|
1541
|
+
expires_at: import_zod16.z.string().datetime().optional(),
|
|
1542
|
+
jurisdiction: import_zod16.z.string().min(1).optional()
|
|
1543
|
+
}).strict();
|
|
1544
|
+
var LiabilityWaiverTermsHashInputSchema = import_zod16.z.object({
|
|
1545
|
+
parties: LiabilityWaiverTermsPartiesSchema,
|
|
1546
|
+
liability_effect: LiabilityDispositionSchema,
|
|
1547
|
+
scope: LiabilityWaiverTermsScopeSchema,
|
|
1548
|
+
conditions: LiabilityWaiverTermsConditionsSchema.optional(),
|
|
1549
|
+
canonical_terms: import_zod16.z.record(import_zod16.z.unknown()).optional()
|
|
1550
|
+
}).strict();
|
|
1551
|
+
var LiabilityWaiverTermsRefV0Schema = import_zod16.z.object({
|
|
1552
|
+
waiver_id: import_zod16.z.string().min(1).optional(),
|
|
1553
|
+
terms_hash: Base64urlSha256Schema,
|
|
1554
|
+
type: import_zod16.z.literal(LIABILITY_WAIVER_TERMS_TYPE_URI),
|
|
1555
|
+
version: import_zod16.z.literal(LIABILITY_WAIVER_TERMS_VERSION)
|
|
1556
|
+
}).strict();
|
|
1557
|
+
var LiabilityWaiverTermsV0Schema = import_zod16.z.object({
|
|
1558
|
+
"@type": import_zod16.z.literal(LIABILITY_WAIVER_TERMS_TYPE_URI),
|
|
1559
|
+
version: import_zod16.z.literal(LIABILITY_WAIVER_TERMS_VERSION),
|
|
1560
|
+
waiver_id: import_zod16.z.string().min(1),
|
|
1561
|
+
terms_hash: Base64urlSha256Schema,
|
|
1562
|
+
parties: LiabilityWaiverTermsPartiesSchema,
|
|
1563
|
+
liability_effect: LiabilityDispositionSchema,
|
|
1564
|
+
scope: LiabilityWaiverTermsScopeSchema,
|
|
1565
|
+
conditions: LiabilityWaiverTermsConditionsSchema.optional(),
|
|
1566
|
+
human_readable_summary: import_zod16.z.string().min(1).optional(),
|
|
1567
|
+
canonical_terms: import_zod16.z.record(import_zod16.z.unknown()).optional()
|
|
1568
|
+
}).strict();
|
|
1505
1569
|
var cachedSha2562 = null;
|
|
1506
1570
|
function loadSha2562() {
|
|
1507
1571
|
if (cachedSha2562) return cachedSha2562;
|
|
@@ -1517,24 +1581,104 @@ function loadSha2562() {
|
|
|
1517
1581
|
sha256 = _require("@noble/hashes/sha2").sha256;
|
|
1518
1582
|
} catch {
|
|
1519
1583
|
throw new Error(
|
|
1520
|
-
"
|
|
1584
|
+
"Liability waiver hashing requires @noble/hashes as a peer dependency. Install it: npm install @noble/hashes"
|
|
1521
1585
|
);
|
|
1522
1586
|
}
|
|
1523
1587
|
}
|
|
1524
1588
|
cachedSha2562 = sha256;
|
|
1525
1589
|
return sha256;
|
|
1526
1590
|
}
|
|
1527
|
-
function
|
|
1591
|
+
function toLiabilityWaiverTermsHashInput(terms) {
|
|
1592
|
+
return {
|
|
1593
|
+
parties: terms.parties,
|
|
1594
|
+
liability_effect: terms.liability_effect,
|
|
1595
|
+
scope: terms.scope,
|
|
1596
|
+
...terms.conditions !== void 0 ? { conditions: terms.conditions } : {},
|
|
1597
|
+
...terms.canonical_terms !== void 0 ? { canonical_terms: terms.canonical_terms } : {}
|
|
1598
|
+
};
|
|
1599
|
+
}
|
|
1600
|
+
function computeLiabilityWaiverTermsHash(input) {
|
|
1528
1601
|
const sha256 = loadSha2562();
|
|
1602
|
+
const canonical = jcsCanonicalize(input);
|
|
1603
|
+
const digest = sha256(new TextEncoder().encode(canonical));
|
|
1604
|
+
return bytesToBase64url(digest);
|
|
1605
|
+
}
|
|
1606
|
+
|
|
1607
|
+
// src/srr-v1.ts
|
|
1608
|
+
var import_zod17 = require("zod");
|
|
1609
|
+
var SRR_V1_TYPE_URI = "https://hlos.ai/schema/SignedRejectionReceiptV1";
|
|
1610
|
+
var SRR_V1_VERSION = 1;
|
|
1611
|
+
var SRR_V1_REJECTION_DOMAIN = "kernel:u:rejection:v1";
|
|
1612
|
+
var SRR_V1_SIGNATURE_ALGORITHM = SRR_SIGNATURE_ALGORITHM;
|
|
1613
|
+
var SignedRejectionReceiptV1Schema = import_zod17.z.object({
|
|
1614
|
+
"@type": import_zod17.z.literal(SRR_V1_TYPE_URI),
|
|
1615
|
+
version: import_zod17.z.literal(SRR_V1_VERSION),
|
|
1616
|
+
receipt_id: import_zod17.z.string().regex(
|
|
1617
|
+
/^srr_[0-9A-HJKMNP-TV-Z]{26}$/i,
|
|
1618
|
+
"receipt_id must be srr_ + 26-char ULID"
|
|
1619
|
+
),
|
|
1620
|
+
crossing_id: import_zod17.z.string().min(1),
|
|
1621
|
+
reason_code: import_zod17.z.string().regex(REASON_CODE_PATTERN, "reason_code must be UPPER_SNAKE_CASE, 3-64 chars"),
|
|
1622
|
+
reason_message: import_zod17.z.string().min(1),
|
|
1623
|
+
details: import_zod17.z.record(import_zod17.z.unknown()).optional(),
|
|
1624
|
+
commitment_hash: Base64urlSha256Schema.optional(),
|
|
1625
|
+
issuer_id: import_zod17.z.string().min(1),
|
|
1626
|
+
rejected_at: import_zod17.z.string().datetime(),
|
|
1627
|
+
issuer_public_key_ref: import_zod17.z.string().min(1),
|
|
1628
|
+
signature_algorithm: import_zod17.z.literal(SRR_V1_SIGNATURE_ALGORITHM),
|
|
1629
|
+
liability_disposition: LiabilityDispositionSchema,
|
|
1630
|
+
waiver_terms_ref: LiabilityWaiverTermsRefV0Schema.optional(),
|
|
1631
|
+
signature: Base64urlEd25519SigSchema
|
|
1632
|
+
}).strict().superRefine((value, ctx) => {
|
|
1633
|
+
if ((value.liability_disposition === "RELEASE" || value.liability_disposition === "TRANSFER") && value.waiver_terms_ref === void 0) {
|
|
1634
|
+
ctx.addIssue({
|
|
1635
|
+
code: import_zod17.z.ZodIssueCode.custom,
|
|
1636
|
+
path: ["waiver_terms_ref"],
|
|
1637
|
+
message: "waiver_terms_ref is required for RELEASE and TRANSFER"
|
|
1638
|
+
});
|
|
1639
|
+
}
|
|
1640
|
+
});
|
|
1641
|
+
|
|
1642
|
+
// src/srr-signing.ts
|
|
1643
|
+
var textEncoder = new TextEncoder();
|
|
1644
|
+
var DOMAIN_BYTES_V0 = textEncoder.encode(SRR_REJECTION_DOMAIN);
|
|
1645
|
+
var DOMAIN_BYTES_V1 = textEncoder.encode(SRR_V1_REJECTION_DOMAIN);
|
|
1646
|
+
var cachedSha2563 = null;
|
|
1647
|
+
function loadSha2563() {
|
|
1648
|
+
if (cachedSha2563) return cachedSha2563;
|
|
1649
|
+
const moduleApi = typeof process.getBuiltinModule === "function" ? process.getBuiltinModule("module") : require("module");
|
|
1650
|
+
const createRequire = moduleApi.createRequire;
|
|
1651
|
+
const requireBase = typeof __filename === "string" ? __filename : `${process.cwd()}/package.json`;
|
|
1652
|
+
const _require = createRequire(requireBase);
|
|
1653
|
+
let sha256;
|
|
1654
|
+
try {
|
|
1655
|
+
sha256 = _require("@noble/hashes/sha2.js").sha256;
|
|
1656
|
+
} catch {
|
|
1657
|
+
try {
|
|
1658
|
+
sha256 = _require("@noble/hashes/sha2").sha256;
|
|
1659
|
+
} catch {
|
|
1660
|
+
throw new Error(
|
|
1661
|
+
"SRR signing requires @noble/hashes as a peer dependency. Install it: npm install @noble/hashes"
|
|
1662
|
+
);
|
|
1663
|
+
}
|
|
1664
|
+
}
|
|
1665
|
+
cachedSha2563 = sha256;
|
|
1666
|
+
return sha256;
|
|
1667
|
+
}
|
|
1668
|
+
function computeSrrSigningPayload(unsignedSrr) {
|
|
1669
|
+
const sha256 = loadSha2563();
|
|
1529
1670
|
const canonical = jcsCanonicalize(unsignedSrr);
|
|
1530
1671
|
const digest = sha256(textEncoder.encode(canonical));
|
|
1531
|
-
const
|
|
1532
|
-
|
|
1533
|
-
|
|
1672
|
+
const domainBytes = unsignedSrr["@type"] === SRR_V1_TYPE_URI ? DOMAIN_BYTES_V1 : unsignedSrr["@type"] === SRR_TYPE_URI ? DOMAIN_BYTES_V0 : (() => {
|
|
1673
|
+
throw new Error("Unsupported SRR type for signing payload construction");
|
|
1674
|
+
})();
|
|
1675
|
+
const payload = new Uint8Array(domainBytes.length + digest.length);
|
|
1676
|
+
payload.set(domainBytes, 0);
|
|
1677
|
+
payload.set(digest, domainBytes.length);
|
|
1534
1678
|
return payload;
|
|
1535
1679
|
}
|
|
1536
1680
|
function computeSrrDigest(signedSrr) {
|
|
1537
|
-
const sha256 =
|
|
1681
|
+
const sha256 = loadSha2563();
|
|
1538
1682
|
const canonical = jcsCanonicalize(signedSrr);
|
|
1539
1683
|
return bytesToBase64url(sha256(textEncoder.encode(canonical)));
|
|
1540
1684
|
}
|
|
@@ -1590,23 +1734,28 @@ async function verifySignedRejectionReceipt(params) {
|
|
|
1590
1734
|
if (!srr || typeof srr !== "object") {
|
|
1591
1735
|
return { valid: false, reason: "SCHEMA_VIOLATION" };
|
|
1592
1736
|
}
|
|
1593
|
-
if (srr.signature_algorithm !== SRR_SIGNATURE_ALGORITHM) {
|
|
1737
|
+
if (typeof srr.signature_algorithm === "string" && srr.signature_algorithm !== SRR_SIGNATURE_ALGORITHM) {
|
|
1594
1738
|
return { valid: false, reason: "UNSUPPORTED_ALGORITHM" };
|
|
1595
1739
|
}
|
|
1596
|
-
const
|
|
1740
|
+
const wireType = srr["@type"];
|
|
1741
|
+
if (wireType !== SRR_V1_TYPE_URI && wireType !== SRR_TYPE_URI) {
|
|
1742
|
+
return { valid: false, reason: "SCHEMA_VIOLATION" };
|
|
1743
|
+
}
|
|
1744
|
+
const parseResult = wireType === SRR_V1_TYPE_URI ? SignedRejectionReceiptV1Schema.safeParse(srr) : SignedRejectionReceiptV0Schema.safeParse(srr);
|
|
1597
1745
|
if (!parseResult.success) {
|
|
1598
1746
|
return { valid: false, reason: "SCHEMA_VIOLATION" };
|
|
1599
1747
|
}
|
|
1748
|
+
const parsedSrr = parseResult.data;
|
|
1600
1749
|
let signingPayload;
|
|
1601
1750
|
try {
|
|
1602
|
-
const { signature, ...unsignedFields } =
|
|
1751
|
+
const { signature, ...unsignedFields } = parsedSrr;
|
|
1603
1752
|
signingPayload = computeSrrSigningPayload(unsignedFields);
|
|
1604
1753
|
} catch {
|
|
1605
1754
|
return { valid: false, reason: "PAYLOAD_CONSTRUCTION_ERROR" };
|
|
1606
1755
|
}
|
|
1607
1756
|
let signatureBytes;
|
|
1608
1757
|
try {
|
|
1609
|
-
signatureBytes = base64urlToBytes(
|
|
1758
|
+
signatureBytes = base64urlToBytes(parsedSrr.signature);
|
|
1610
1759
|
} catch {
|
|
1611
1760
|
return { valid: false, reason: "INVALID_SIGNATURE" };
|
|
1612
1761
|
}
|
|
@@ -1663,7 +1812,16 @@ async function verifySignedRejectionReceipt(params) {
|
|
|
1663
1812
|
KernelErrorCodeSchema,
|
|
1664
1813
|
KernelErrorSchema,
|
|
1665
1814
|
KernelOkSchema,
|
|
1815
|
+
LIABILITY_WAIVER_TERMS_TYPE_URI,
|
|
1816
|
+
LIABILITY_WAIVER_TERMS_VERSION,
|
|
1666
1817
|
LiabilityAttestationContentSchema,
|
|
1818
|
+
LiabilityDispositionSchema,
|
|
1819
|
+
LiabilityWaiverTermsConditionsSchema,
|
|
1820
|
+
LiabilityWaiverTermsHashInputSchema,
|
|
1821
|
+
LiabilityWaiverTermsPartiesSchema,
|
|
1822
|
+
LiabilityWaiverTermsRefV0Schema,
|
|
1823
|
+
LiabilityWaiverTermsScopeSchema,
|
|
1824
|
+
LiabilityWaiverTermsV0Schema,
|
|
1667
1825
|
LogInclusionProofSchema,
|
|
1668
1826
|
NA_ID_PREFIX,
|
|
1669
1827
|
NotarizeResponseSchema,
|
|
@@ -1690,6 +1848,10 @@ async function verifySignedRejectionReceipt(params) {
|
|
|
1690
1848
|
SRR_REJECTION_DOMAIN,
|
|
1691
1849
|
SRR_SIGNATURE_ALGORITHM,
|
|
1692
1850
|
SRR_TYPE_URI,
|
|
1851
|
+
SRR_V1_REJECTION_DOMAIN,
|
|
1852
|
+
SRR_V1_SIGNATURE_ALGORITHM,
|
|
1853
|
+
SRR_V1_TYPE_URI,
|
|
1854
|
+
SRR_V1_VERSION,
|
|
1693
1855
|
SRR_VERSION,
|
|
1694
1856
|
SURFACES,
|
|
1695
1857
|
SettlementAnchorContentSchema,
|
|
@@ -1700,6 +1862,7 @@ async function verifySignedRejectionReceipt(params) {
|
|
|
1700
1862
|
SignedReceiptV0LooseSchema,
|
|
1701
1863
|
SignedReceiptV0Schema,
|
|
1702
1864
|
SignedRejectionReceiptV0Schema,
|
|
1865
|
+
SignedRejectionReceiptV1Schema,
|
|
1703
1866
|
StackConnectionSchema,
|
|
1704
1867
|
StackProviderSchema,
|
|
1705
1868
|
StackSchema,
|
|
@@ -1717,6 +1880,7 @@ async function verifySignedRejectionReceipt(params) {
|
|
|
1717
1880
|
base64urlToBytes,
|
|
1718
1881
|
bytesToBase64url,
|
|
1719
1882
|
computeContentHash,
|
|
1883
|
+
computeLiabilityWaiverTermsHash,
|
|
1720
1884
|
computeReceiptHash,
|
|
1721
1885
|
computeSrrDigest,
|
|
1722
1886
|
computeSrrSigningPayload,
|
|
@@ -1740,6 +1904,7 @@ async function verifySignedRejectionReceipt(params) {
|
|
|
1740
1904
|
kernelError,
|
|
1741
1905
|
kernelOk,
|
|
1742
1906
|
success,
|
|
1907
|
+
toLiabilityWaiverTermsHashInput,
|
|
1743
1908
|
validateTimeWindow,
|
|
1744
1909
|
verifyAAR,
|
|
1745
1910
|
verifyDetachedEd25519,
|