@hazbase/simplicity 0.1.1 → 0.2.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.
Files changed (39) hide show
  1. package/README.md +143 -1531
  2. package/dist/cli.js +1128 -1
  3. package/dist/client/SimplicityClient.d.ts +30 -3
  4. package/dist/client/SimplicityClient.js +28 -0
  5. package/dist/core/lineage.d.ts +18 -0
  6. package/dist/core/lineage.js +30 -0
  7. package/dist/core/reporting.d.ts +22 -0
  8. package/dist/core/reporting.js +40 -0
  9. package/dist/core/schnorr.d.ts +3 -3
  10. package/dist/core/schnorr.js +19 -7
  11. package/dist/core/types.d.ts +256 -5
  12. package/dist/docs/definitions/fund-capital-call-refund-only.simf +36 -2
  13. package/dist/docs/definitions/receivable-definition.json +10 -0
  14. package/dist/docs/definitions/receivable-funding-claim.json +13 -0
  15. package/dist/docs/definitions/receivable-funding-claim.simf +58 -0
  16. package/dist/docs/definitions/receivable-repayment-claim-partial.json +13 -0
  17. package/dist/docs/definitions/receivable-repayment-claim.json +13 -0
  18. package/dist/docs/definitions/receivable-repayment-claim.simf +59 -0
  19. package/dist/docs/definitions/receivable-state-funded.json +21 -0
  20. package/dist/docs/definitions/receivable-state-originated.json +20 -0
  21. package/dist/docs/definitions/receivable-state-partially-repaid.json +21 -0
  22. package/dist/docs/definitions/receivable-state-repaid.json +21 -0
  23. package/dist/domain/bond.d.ts +82 -15
  24. package/dist/domain/bond.js +159 -10
  25. package/dist/domain/bondValidation.d.ts +31 -1
  26. package/dist/domain/bondValidation.js +73 -9
  27. package/dist/domain/fund.d.ts +451 -68
  28. package/dist/domain/fund.js +460 -88
  29. package/dist/domain/fundValidation.d.ts +33 -3
  30. package/dist/domain/fundValidation.js +137 -5
  31. package/dist/domain/policies.d.ts +13 -0
  32. package/dist/domain/policies.js +50 -30
  33. package/dist/domain/receivable.d.ts +825 -0
  34. package/dist/domain/receivable.js +1385 -0
  35. package/dist/domain/receivableValidation.d.ts +150 -0
  36. package/dist/domain/receivableValidation.js +874 -0
  37. package/dist/index.d.ts +5 -3
  38. package/dist/index.js +55 -3
  39. package/package.json +6 -1
@@ -0,0 +1,10 @@
1
+ {
2
+ "receivableId": "REC-001",
3
+ "originatorEntityId": "originator-1",
4
+ "debtorEntityId": "debtor-1",
5
+ "currencyAssetId": "bitcoin",
6
+ "faceValue": 10000,
7
+ "dueDate": "2027-12-31T00:00:00Z",
8
+ "controllerXonly": "3333333333333333333333333333333333333333333333333333333333333333",
9
+ "originatorClaimantXonly": "1111111111111111111111111111111111111111111111111111111111111111"
10
+ }
@@ -0,0 +1,13 @@
1
+ {
2
+ "claimId": "REC-001-FUNDING-CLAIM",
3
+ "claimKind": "FUNDING",
4
+ "receivableId": "REC-001",
5
+ "currentStateHash": "13147d187ce3200d7044d73d7b86b93140c43f29dd048f919569f5eb7b47c562",
6
+ "currentStatus": "FUNDED",
7
+ "payerEntityId": "fund-1",
8
+ "payeeEntityId": "originator-1",
9
+ "claimantXonly": "1111111111111111111111111111111111111111111111111111111111111111",
10
+ "currencyAssetId": "bitcoin",
11
+ "amountSat": 10000,
12
+ "eventTimestamp": "2027-01-02T00:00:00Z"
13
+ }
@@ -0,0 +1,58 @@
1
+ /*
2
+ * Receivable funding claim contract.
3
+ *
4
+ * After a receivable moves into FUNDED state off-chain, the funder/SPV funds
5
+ * this one-shot claim contract and the committed claimant releases the payout
6
+ * to the originator-side destination. Runtime output binding is optional.
7
+ */
8
+ fn not(bit: bool) -> bool {
9
+ <u1>::into(jet::complement_1(<bool>::into(bit)))
10
+ }
11
+
12
+ fn require_definition_anchor() {
13
+ let anchored_definition_hash: u256 = 0x{{DEFINITION_HASH}};
14
+ let zero_hash: u256 = 0x0000000000000000000000000000000000000000000000000000000000000000;
15
+ assert!(not(jet::eq_256(anchored_definition_hash, zero_hash)));
16
+ }
17
+
18
+ fn require_state_anchor() {
19
+ let anchored_state_hash: u256 = 0x{{STATE_HASH}};
20
+ let zero_hash: u256 = 0x0000000000000000000000000000000000000000000000000000000000000000;
21
+ assert!(not(jet::eq_256(anchored_state_hash, zero_hash)));
22
+ }
23
+
24
+ fn require_output_shape(expected_output_hash: u256, expected_output_script_hash: u256, binding_mode: u8) {
25
+ match jet::eq_8(binding_mode, 1) {
26
+ true => {
27
+ let actual_output_hash: u256 = match jet::output_hash(0) {
28
+ Some(output_hash : u256) => output_hash,
29
+ None => panic!(),
30
+ };
31
+ assert!(jet::eq_32(jet::num_outputs(), 2));
32
+ assert!(unwrap(jet::output_is_fee(1)));
33
+ assert!(jet::eq_256(actual_output_hash, expected_output_hash));
34
+ },
35
+ false => {
36
+ match jet::eq_8(binding_mode, 2) {
37
+ true => {
38
+ let actual_output_script_hash: u256 = unwrap(jet::output_script_hash(0));
39
+ assert!(jet::eq_32(jet::num_outputs(), 2));
40
+ assert!(unwrap(jet::output_is_fee(1)));
41
+ assert!(jet::eq_256(actual_output_script_hash, expected_output_script_hash));
42
+ },
43
+ false => {},
44
+ }
45
+ },
46
+ }
47
+ }
48
+
49
+ fn main() {
50
+ require_definition_anchor();
51
+ require_state_anchor();
52
+ let expected_output_hash: u256 = witness::EXPECTED_PAYOUT_OUTPUT_HASH;
53
+ let expected_output_script_hash: u256 = witness::EXPECTED_PAYOUT_OUTPUT_SCRIPT_HASH;
54
+ let binding_mode: u8 = witness::OUTPUT_BINDING_MODE;
55
+ require_output_shape(expected_output_hash, expected_output_script_hash, binding_mode);
56
+ let claimant: Pubkey = 0x{{CLAIMANT_XONLY}};
57
+ jet::bip_0340_verify((claimant, jet::sig_all_hash()), witness::SIGNER_SIGNATURE)
58
+ }
@@ -0,0 +1,13 @@
1
+ {
2
+ "claimId": "REC-001-REPAYMENT-CLAIM-PARTIAL",
3
+ "claimKind": "REPAYMENT",
4
+ "receivableId": "REC-001",
5
+ "currentStateHash": "34e4db6639ad5b3ccb555320af22fb0eca2ab393ff198602ce5ca69d398cec31",
6
+ "currentStatus": "PARTIALLY_REPAID",
7
+ "payerEntityId": "debtor-1",
8
+ "payeeEntityId": "fund-1",
9
+ "claimantXonly": "2222222222222222222222222222222222222222222222222222222222222222",
10
+ "currencyAssetId": "bitcoin",
11
+ "amountSat": 4000,
12
+ "eventTimestamp": "2027-02-01T00:00:00Z"
13
+ }
@@ -0,0 +1,13 @@
1
+ {
2
+ "claimId": "REC-001-REPAYMENT-CLAIM-FINAL",
3
+ "claimKind": "REPAYMENT",
4
+ "receivableId": "REC-001",
5
+ "currentStateHash": "a18fdc99bf37de415bfa242a387cdb41b943d2581bfe177aec51c3e42e9e40bf",
6
+ "currentStatus": "REPAID",
7
+ "payerEntityId": "debtor-1",
8
+ "payeeEntityId": "fund-1",
9
+ "claimantXonly": "2222222222222222222222222222222222222222222222222222222222222222",
10
+ "currencyAssetId": "bitcoin",
11
+ "amountSat": 6000,
12
+ "eventTimestamp": "2027-03-01T00:00:00Z"
13
+ }
@@ -0,0 +1,59 @@
1
+ /*
2
+ * Receivable repayment claim contract.
3
+ *
4
+ * After a receivable moves into PARTIALLY_REPAID or REPAID state off-chain,
5
+ * the debtor-side payment funds this one-shot claim contract and the committed
6
+ * claimant releases the payout to the current holder-side destination. Runtime
7
+ * output binding is optional.
8
+ */
9
+ fn not(bit: bool) -> bool {
10
+ <u1>::into(jet::complement_1(<bool>::into(bit)))
11
+ }
12
+
13
+ fn require_definition_anchor() {
14
+ let anchored_definition_hash: u256 = 0x{{DEFINITION_HASH}};
15
+ let zero_hash: u256 = 0x0000000000000000000000000000000000000000000000000000000000000000;
16
+ assert!(not(jet::eq_256(anchored_definition_hash, zero_hash)));
17
+ }
18
+
19
+ fn require_state_anchor() {
20
+ let anchored_state_hash: u256 = 0x{{STATE_HASH}};
21
+ let zero_hash: u256 = 0x0000000000000000000000000000000000000000000000000000000000000000;
22
+ assert!(not(jet::eq_256(anchored_state_hash, zero_hash)));
23
+ }
24
+
25
+ fn require_output_shape(expected_output_hash: u256, expected_output_script_hash: u256, binding_mode: u8) {
26
+ match jet::eq_8(binding_mode, 1) {
27
+ true => {
28
+ let actual_output_hash: u256 = match jet::output_hash(0) {
29
+ Some(output_hash : u256) => output_hash,
30
+ None => panic!(),
31
+ };
32
+ assert!(jet::eq_32(jet::num_outputs(), 2));
33
+ assert!(unwrap(jet::output_is_fee(1)));
34
+ assert!(jet::eq_256(actual_output_hash, expected_output_hash));
35
+ },
36
+ false => {
37
+ match jet::eq_8(binding_mode, 2) {
38
+ true => {
39
+ let actual_output_script_hash: u256 = unwrap(jet::output_script_hash(0));
40
+ assert!(jet::eq_32(jet::num_outputs(), 2));
41
+ assert!(unwrap(jet::output_is_fee(1)));
42
+ assert!(jet::eq_256(actual_output_script_hash, expected_output_script_hash));
43
+ },
44
+ false => {},
45
+ }
46
+ },
47
+ }
48
+ }
49
+
50
+ fn main() {
51
+ require_definition_anchor();
52
+ require_state_anchor();
53
+ let expected_output_hash: u256 = witness::EXPECTED_PAYOUT_OUTPUT_HASH;
54
+ let expected_output_script_hash: u256 = witness::EXPECTED_PAYOUT_OUTPUT_SCRIPT_HASH;
55
+ let binding_mode: u8 = witness::OUTPUT_BINDING_MODE;
56
+ require_output_shape(expected_output_hash, expected_output_script_hash, binding_mode);
57
+ let claimant: Pubkey = 0x{{CLAIMANT_XONLY}};
58
+ jet::bip_0340_verify((claimant, jet::sig_all_hash()), witness::SIGNER_SIGNATURE)
59
+ }
@@ -0,0 +1,21 @@
1
+ {
2
+ "stateId": "REC-001-S1",
3
+ "receivableId": "REC-001",
4
+ "originatorEntityId": "originator-1",
5
+ "debtorEntityId": "debtor-1",
6
+ "holderEntityId": "fund-1",
7
+ "currencyAssetId": "bitcoin",
8
+ "controllerXonly": "3333333333333333333333333333333333333333333333333333333333333333",
9
+ "holderClaimantXonly": "2222222222222222222222222222222222222222222222222222222222222222",
10
+ "faceValue": 10000,
11
+ "outstandingAmount": 10000,
12
+ "repaidAmount": 0,
13
+ "status": "FUNDED",
14
+ "createdAt": "2027-01-02T00:00:00Z",
15
+ "previousStateHash": "cdd1a8e867611a0bf486c35a7811c80c2459f28ca988c22f789fbacdd4ee5c9e",
16
+ "lastTransition": {
17
+ "type": "FUND",
18
+ "amount": 10000,
19
+ "at": "2027-01-02T00:00:00Z"
20
+ }
21
+ }
@@ -0,0 +1,20 @@
1
+ {
2
+ "stateId": "REC-001-S0",
3
+ "receivableId": "REC-001",
4
+ "originatorEntityId": "originator-1",
5
+ "debtorEntityId": "debtor-1",
6
+ "holderEntityId": "originator-1",
7
+ "currencyAssetId": "bitcoin",
8
+ "controllerXonly": "3333333333333333333333333333333333333333333333333333333333333333",
9
+ "holderClaimantXonly": "1111111111111111111111111111111111111111111111111111111111111111",
10
+ "faceValue": 10000,
11
+ "outstandingAmount": 10000,
12
+ "repaidAmount": 0,
13
+ "status": "ORIGINATED",
14
+ "createdAt": "2027-01-01T00:00:00Z",
15
+ "lastTransition": {
16
+ "type": "ORIGINATE",
17
+ "amount": 10000,
18
+ "at": "2027-01-01T00:00:00Z"
19
+ }
20
+ }
@@ -0,0 +1,21 @@
1
+ {
2
+ "stateId": "REC-001-S2",
3
+ "receivableId": "REC-001",
4
+ "originatorEntityId": "originator-1",
5
+ "debtorEntityId": "debtor-1",
6
+ "holderEntityId": "fund-1",
7
+ "currencyAssetId": "bitcoin",
8
+ "controllerXonly": "3333333333333333333333333333333333333333333333333333333333333333",
9
+ "holderClaimantXonly": "2222222222222222222222222222222222222222222222222222222222222222",
10
+ "faceValue": 10000,
11
+ "outstandingAmount": 6000,
12
+ "repaidAmount": 4000,
13
+ "status": "PARTIALLY_REPAID",
14
+ "createdAt": "2027-02-01T00:00:00Z",
15
+ "previousStateHash": "13147d187ce3200d7044d73d7b86b93140c43f29dd048f919569f5eb7b47c562",
16
+ "lastTransition": {
17
+ "type": "REPAY",
18
+ "amount": 4000,
19
+ "at": "2027-02-01T00:00:00Z"
20
+ }
21
+ }
@@ -0,0 +1,21 @@
1
+ {
2
+ "stateId": "REC-001-S3",
3
+ "receivableId": "REC-001",
4
+ "originatorEntityId": "originator-1",
5
+ "debtorEntityId": "debtor-1",
6
+ "holderEntityId": "fund-1",
7
+ "currencyAssetId": "bitcoin",
8
+ "controllerXonly": "3333333333333333333333333333333333333333333333333333333333333333",
9
+ "holderClaimantXonly": "2222222222222222222222222222222222222222222222222222222222222222",
10
+ "faceValue": 10000,
11
+ "outstandingAmount": 0,
12
+ "repaidAmount": 10000,
13
+ "status": "REPAID",
14
+ "createdAt": "2027-03-01T00:00:00Z",
15
+ "previousStateHash": "34e4db6639ad5b3ccb555320af22fb0eca2ab393ff198602ce5ca69d398cec31",
16
+ "lastTransition": {
17
+ "type": "REPAY",
18
+ "amount": 6000,
19
+ "at": "2027-03-01T00:00:00Z"
20
+ }
21
+ }
@@ -64,7 +64,15 @@ export declare function buildBondPayload(sdk: SimplicityClient, input: {
64
64
  definitionValue?: BondDefinition;
65
65
  issuancePath?: string;
66
66
  issuanceValue?: BondIssuanceState;
67
+ issuanceHistoryPaths?: string[];
68
+ issuanceHistoryValues?: BondIssuanceState[];
67
69
  }): Promise<{
70
+ issuanceHistory?: import("../core/types").StateDocumentDescriptor[] | undefined;
71
+ issuanceHistoryValues?: BondIssuanceState[] | undefined;
72
+ issuanceHistorySummaries?: {
73
+ canonicalJson: string;
74
+ hash: string;
75
+ }[] | undefined;
68
76
  artifact: SimplicityArtifact;
69
77
  payload: {
70
78
  bondId: string;
@@ -109,8 +117,76 @@ export declare function buildBondPayload(sdk: SimplicityClient, input: {
109
117
  onChainAnchorVerified: boolean;
110
118
  effectiveMode: "none" | import("../core/types").DefinitionAnchorMode;
111
119
  };
120
+ issuanceLineageTrust: import("../core/types").BondIssuanceLineageTrust | undefined;
112
121
  };
113
122
  }>;
123
+ export declare function verifyIssuanceHistory(sdk: SimplicityClient, input: {
124
+ definitionPath?: string;
125
+ definitionValue?: BondDefinition;
126
+ issuanceHistoryPaths?: string[];
127
+ issuanceHistoryValues?: BondIssuanceState[];
128
+ }): Promise<{
129
+ issuanceHistory: import("../core/types").StateDocumentDescriptor[];
130
+ issuanceHistoryValues: BondIssuanceState[];
131
+ issuanceHistorySummaries: {
132
+ canonicalJson: string;
133
+ hash: string;
134
+ }[];
135
+ checks: {
136
+ chainLength: number;
137
+ latestStatus: import("../core/types").BondIssuanceStatus | undefined;
138
+ startsAtGenesis: boolean;
139
+ previousStateHashLinked: boolean;
140
+ issuanceIdConsistent: boolean;
141
+ bondIdConsistent: boolean;
142
+ currencyConsistent: boolean;
143
+ controllerConsistent: boolean;
144
+ issuerEntityConsistent: boolean;
145
+ issuedPrincipalConsistent: boolean;
146
+ allPreviousStateHashMatch: boolean;
147
+ allRedemptionArithmeticValid: boolean;
148
+ allStatusProgressionValid: boolean;
149
+ allTransitionIdentitiesMatch: boolean;
150
+ fullHistoryVerified: boolean;
151
+ transitionChecks: {
152
+ issuanceIdMatch: boolean;
153
+ bondIdMatch: boolean;
154
+ currencyMatch: boolean;
155
+ controllerMatch: boolean;
156
+ issuerEntityMatch: boolean;
157
+ issuedPrincipalMatch: boolean;
158
+ previousStateHashMatch: boolean;
159
+ redemptionArithmeticValid: boolean;
160
+ statusProgressionValid: boolean;
161
+ }[];
162
+ };
163
+ report: {
164
+ issuanceLineageTrust: import("../core/types").BondIssuanceLineageTrust | undefined;
165
+ artifactTrust: {
166
+ definition: {
167
+ artifactMatch: boolean;
168
+ onChainAnchorPresent: boolean;
169
+ onChainAnchorVerified: boolean;
170
+ effectiveMode: "none" | import("../core/types").DefinitionAnchorMode;
171
+ };
172
+ state: {
173
+ artifactMatch: boolean;
174
+ onChainAnchorPresent: boolean;
175
+ onChainAnchorVerified: boolean;
176
+ effectiveMode: "none" | import("../core/types").DefinitionAnchorMode;
177
+ };
178
+ };
179
+ stateTrust: {
180
+ artifactMatch: boolean;
181
+ onChainAnchorPresent: boolean;
182
+ onChainAnchorVerified: boolean;
183
+ effectiveMode: "none" | import("../core/types").DefinitionAnchorMode;
184
+ };
185
+ };
186
+ definition?: import("../core/types").DefinitionDescriptor | undefined;
187
+ definitionValue?: BondDefinition | undefined;
188
+ verified: boolean;
189
+ }>;
114
190
  export declare function summarizeExpectedOutputDescriptor(descriptor: BondExpectedOutputDescriptor): {
115
191
  canonicalJson: string;
116
192
  hash: string;
@@ -493,6 +569,8 @@ export declare function buildEvidenceBundle(sdk: SimplicityClient, input: {
493
569
  definitionValue?: BondDefinition;
494
570
  issuancePath?: string;
495
571
  issuanceValue?: BondIssuanceState;
572
+ issuanceHistoryPaths?: string[];
573
+ issuanceHistoryValues?: BondIssuanceState[];
496
574
  settlementDescriptorValue?: BondSettlementDescriptor;
497
575
  closingDescriptorValue?: BondClosingDescriptor;
498
576
  transitionValue?: unknown;
@@ -751,6 +829,8 @@ export declare function exportFinalityPayload(sdk: SimplicityClient, input: {
751
829
  definitionValue?: BondDefinition;
752
830
  issuancePath?: string;
753
831
  issuanceValue?: BondIssuanceState;
832
+ issuanceHistoryPaths?: string[];
833
+ issuanceHistoryValues?: BondIssuanceState[];
754
834
  settlementDescriptorValue?: BondSettlementDescriptor;
755
835
  closingDescriptorValue?: BondClosingDescriptor;
756
836
  }): Promise<{
@@ -798,22 +878,9 @@ export declare function exportFinalityPayload(sdk: SimplicityClient, input: {
798
878
  onChainAnchorVerified: boolean;
799
879
  effectiveMode: "none" | import("../core/types").DefinitionAnchorMode;
800
880
  };
881
+ issuanceLineageTrust: import("../core/types").BondIssuanceLineageTrust | undefined;
801
882
  };
802
- trustSummary: {
803
- definition: {
804
- artifactMatch: boolean;
805
- onChainAnchorPresent: boolean;
806
- onChainAnchorVerified: boolean;
807
- effectiveMode: "none" | import("../core/types").DefinitionAnchorMode;
808
- };
809
- issuance: {
810
- artifactMatch: boolean;
811
- onChainAnchorPresent: boolean;
812
- onChainAnchorVerified: boolean;
813
- effectiveMode: "none" | import("../core/types").DefinitionAnchorMode;
814
- };
815
- bindingMode: BondOutputBindingMode;
816
- };
883
+ trustSummary: import("../core/types").VerificationTrustSummary;
817
884
  evidenceSummary: {
818
885
  definitionHash: string;
819
886
  issuanceHash: string;
@@ -40,6 +40,7 @@ exports.defineBond = defineBond;
40
40
  exports.verifyBond = verifyBond;
41
41
  exports.loadBond = loadBond;
42
42
  exports.buildBondPayload = buildBondPayload;
43
+ exports.verifyIssuanceHistory = verifyIssuanceHistory;
43
44
  exports.summarizeExpectedOutputDescriptor = summarizeExpectedOutputDescriptor;
44
45
  exports.validateExpectedOutputDescriptor = validateExpectedOutputDescriptor;
45
46
  exports.buildExpectedOutputDescriptor = buildExpectedOutputDescriptor;
@@ -107,6 +108,7 @@ exports.inspectBondClosing = inspectBondClosing;
107
108
  exports.executeBondClosing = executeBondClosing;
108
109
  const node_fs_1 = require("node:fs");
109
110
  const node_path_1 = __importDefault(require("node:path"));
111
+ const reporting_1 = require("../core/reporting");
110
112
  const summary_1 = require("../core/summary");
111
113
  const outputBinding_1 = require("../core/outputBinding");
112
114
  const bondSettlementValidation_1 = require("./bondSettlementValidation");
@@ -130,6 +132,94 @@ function resolveBondDocsAsset(filename) {
130
132
  }
131
133
  return cwdCandidate;
132
134
  }
135
+ async function loadIssuanceHistoryDocuments(sdk, input) {
136
+ const results = [];
137
+ for (const issuancePath of input.issuanceHistoryPaths ?? []) {
138
+ const state = await sdk.loadStateDocument({
139
+ type: "bond-issuance",
140
+ id: "BOND-ISSUANCE-HISTORY",
141
+ jsonPath: issuancePath,
142
+ });
143
+ const value = (0, bondValidation_1.validateBondIssuanceState)(JSON.parse(state.canonicalJson));
144
+ results.push({
145
+ state,
146
+ value,
147
+ summary: (0, bondValidation_1.summarizeBondIssuanceState)(value),
148
+ });
149
+ }
150
+ for (const issuanceValue of input.issuanceHistoryValues ?? []) {
151
+ const value = (0, bondValidation_1.validateBondIssuanceState)(issuanceValue);
152
+ const state = await sdk.loadStateDocument({
153
+ type: "bond-issuance",
154
+ id: value.issuanceId,
155
+ value,
156
+ });
157
+ results.push({
158
+ state,
159
+ value,
160
+ summary: (0, bondValidation_1.summarizeBondIssuanceState)(value),
161
+ });
162
+ }
163
+ return results;
164
+ }
165
+ function buildBondIssuanceLineageTrust(checks) {
166
+ const identityConsistent = checks.issuanceIdConsistent
167
+ && checks.bondIdConsistent
168
+ && checks.currencyConsistent
169
+ && checks.controllerConsistent
170
+ && checks.issuerEntityConsistent
171
+ && checks.issuedPrincipalConsistent
172
+ && checks.allTransitionIdentitiesMatch;
173
+ return {
174
+ ...(0, reporting_1.buildLineageTrustBase)({
175
+ lineageKind: "state-history",
176
+ chainLength: checks.chainLength,
177
+ latestOrdinal: Math.max(0, checks.chainLength - 1),
178
+ allHashLinksVerified: checks.previousStateHashLinked && checks.allPreviousStateHashMatch,
179
+ identityConsistent,
180
+ fullLineageVerified: checks.fullHistoryVerified,
181
+ }),
182
+ latestStatus: checks.latestStatus,
183
+ startsAtGenesis: checks.startsAtGenesis,
184
+ previousStateHashLinked: checks.previousStateHashLinked,
185
+ issuanceIdConsistent: checks.issuanceIdConsistent,
186
+ bondIdConsistent: checks.bondIdConsistent,
187
+ currencyConsistent: checks.currencyConsistent,
188
+ controllerConsistent: checks.controllerConsistent,
189
+ issuerEntityConsistent: checks.issuerEntityConsistent,
190
+ issuedPrincipalConsistent: checks.issuedPrincipalConsistent,
191
+ allPreviousStateHashMatch: checks.allPreviousStateHashMatch,
192
+ allRedemptionArithmeticValid: checks.allRedemptionArithmeticValid,
193
+ allStatusProgressionValid: checks.allStatusProgressionValid,
194
+ allTransitionIdentitiesMatch: checks.allTransitionIdentitiesMatch,
195
+ fullHistoryVerified: checks.fullHistoryVerified,
196
+ };
197
+ }
198
+ function buildEmptyBondDefinitionTrust() {
199
+ return {
200
+ artifactMatch: false,
201
+ onChainAnchorPresent: false,
202
+ onChainAnchorVerified: false,
203
+ effectiveMode: "none",
204
+ };
205
+ }
206
+ function buildEmptyBondStateTrust() {
207
+ return {
208
+ artifactMatch: false,
209
+ onChainAnchorPresent: false,
210
+ onChainAnchorVerified: false,
211
+ effectiveMode: "none",
212
+ };
213
+ }
214
+ function buildBaseBondReport(input) {
215
+ return (0, reporting_1.buildVerificationTrustSections)({
216
+ definitionTrust: input?.definitionTrust,
217
+ stateTrust: input?.stateTrust,
218
+ requireArtifactTrust: input?.requireArtifactTrust,
219
+ emptyDefinitionTrust: buildEmptyBondDefinitionTrust(),
220
+ emptyStateTrust: buildEmptyBondStateTrust(),
221
+ });
222
+ }
133
223
  async function defineBond(sdk, input) {
134
224
  const definitionSource = resolveValueOrPath({
135
225
  pathValue: input.definitionPath,
@@ -246,6 +336,15 @@ async function buildBondPayload(sdk, input) {
246
336
  const definitionValue = (0, bondValidation_1.validateBondDefinition)(JSON.parse(verification.definition.definition.canonicalJson));
247
337
  const issuanceValue = (0, bondValidation_1.validateBondIssuanceState)(JSON.parse(verification.issuance.state.canonicalJson));
248
338
  const issuanceSummary = (0, bondValidation_1.summarizeBondIssuanceState)(issuanceValue);
339
+ const issuanceHistory = input.issuanceHistoryPaths || input.issuanceHistoryValues
340
+ ? await loadIssuanceHistoryDocuments(sdk, {
341
+ issuanceHistoryPaths: input.issuanceHistoryPaths,
342
+ issuanceHistoryValues: input.issuanceHistoryValues,
343
+ })
344
+ : [];
345
+ const lineageChecks = issuanceHistory.length > 0
346
+ ? (0, bondValidation_1.verifyBondIssuanceHistory)({ history: issuanceHistory.map((entry) => entry.value) })
347
+ : undefined;
249
348
  return {
250
349
  artifact: verification.artifact,
251
350
  payload: {
@@ -278,6 +377,45 @@ async function buildBondPayload(sdk, input) {
278
377
  trust: {
279
378
  definitionTrust: verification.definition.trust,
280
379
  issuanceTrust: verification.issuance.trust,
380
+ issuanceLineageTrust: lineageChecks ? buildBondIssuanceLineageTrust(lineageChecks) : undefined,
381
+ },
382
+ ...(issuanceHistory.length > 0
383
+ ? {
384
+ issuanceHistory: issuanceHistory.map((entry) => entry.state),
385
+ issuanceHistoryValues: issuanceHistory.map((entry) => entry.value),
386
+ issuanceHistorySummaries: issuanceHistory.map((entry) => entry.summary),
387
+ }
388
+ : {}),
389
+ };
390
+ }
391
+ async function verifyIssuanceHistory(sdk, input) {
392
+ const definitionSource = resolveValueOrPath({
393
+ pathValue: input.definitionPath,
394
+ objectValue: input.definitionValue,
395
+ });
396
+ const definition = input.definitionPath || input.definitionValue
397
+ ? await sdk.loadDefinition({
398
+ type: "bond",
399
+ id: input.definitionValue?.bondId ?? "BOND-2026-001",
400
+ ...definitionSource,
401
+ })
402
+ : undefined;
403
+ const definitionValue = definition ? (0, bondValidation_1.validateBondDefinition)(JSON.parse(definition.canonicalJson)) : undefined;
404
+ const issuanceHistory = await loadIssuanceHistoryDocuments(sdk, input);
405
+ const checks = (0, bondValidation_1.verifyBondIssuanceHistory)({ history: issuanceHistory.map((entry) => entry.value) });
406
+ if (definitionValue) {
407
+ (0, bondValidation_1.validateBondCrossChecks)(definitionValue, issuanceHistory.at(-1).value);
408
+ }
409
+ return {
410
+ verified: checks.fullHistoryVerified,
411
+ ...(definition ? { definition, definitionValue } : {}),
412
+ issuanceHistory: issuanceHistory.map((entry) => entry.state),
413
+ issuanceHistoryValues: issuanceHistory.map((entry) => entry.value),
414
+ issuanceHistorySummaries: issuanceHistory.map((entry) => entry.summary),
415
+ checks,
416
+ report: {
417
+ ...buildBaseBondReport({ requireArtifactTrust: true }),
418
+ issuanceLineageTrust: buildBondIssuanceLineageTrust(checks),
281
419
  },
282
420
  };
283
421
  }
@@ -932,6 +1070,15 @@ async function buildEvidenceBundle(sdk, input) {
932
1070
  });
933
1071
  const definition = verification.definition.definition;
934
1072
  const issuance = verification.issuance.state;
1073
+ const issuanceHistory = input.issuanceHistoryPaths || input.issuanceHistoryValues
1074
+ ? await loadIssuanceHistoryDocuments(sdk, {
1075
+ issuanceHistoryPaths: input.issuanceHistoryPaths,
1076
+ issuanceHistoryValues: input.issuanceHistoryValues,
1077
+ })
1078
+ : [];
1079
+ const lineageChecks = issuanceHistory.length > 0
1080
+ ? (0, bondValidation_1.verifyBondIssuanceHistory)({ history: issuanceHistory.map((entry) => entry.value) })
1081
+ : undefined;
935
1082
  const settlementCanonicalJson = input.settlementDescriptorValue
936
1083
  ? (0, bondSettlementValidation_1.summarizeBondSettlementDescriptor)(input.settlementDescriptorValue).canonicalJson
937
1084
  : null;
@@ -977,11 +1124,11 @@ async function buildEvidenceBundle(sdk, input) {
977
1124
  }
978
1125
  : undefined,
979
1126
  trust: {
980
- artifactTrust: {
981
- definition: verification.definition.trust,
982
- state: verification.issuance.trust,
983
- },
984
- stateTrust: verification.issuance.trust,
1127
+ ...buildBaseBondReport({
1128
+ definitionTrust: verification.definition.trust,
1129
+ stateTrust: verification.issuance.trust,
1130
+ }),
1131
+ issuanceLineageTrust: lineageChecks ? buildBondIssuanceLineageTrust(lineageChecks) : undefined,
985
1132
  settlementTrust: input.settlementDescriptorValue
986
1133
  ? {
987
1134
  descriptorHashMatch: true,
@@ -989,6 +1136,12 @@ async function buildEvidenceBundle(sdk, input) {
989
1136
  }
990
1137
  : undefined,
991
1138
  },
1139
+ trustSummary: (0, reporting_1.buildVerificationTrustSummary)({
1140
+ definitionTrust: verification.definition.trust,
1141
+ stateTrust: verification.issuance.trust,
1142
+ bindingMode: input.settlementDescriptorValue?.outputBindingMode ?? "none",
1143
+ lineageTrust: lineageChecks ? buildBondIssuanceLineageTrust(lineageChecks) : undefined,
1144
+ }),
992
1145
  renderedSourceHash: renderedSourceHash ?? undefined,
993
1146
  sourceVerificationMode: renderedSourceHash ? "source-reloaded" : "artifact-only",
994
1147
  compiled: {
@@ -1059,11 +1212,7 @@ async function exportFinalityPayload(sdk, input) {
1059
1212
  payload: bondPayload.payload,
1060
1213
  bindingMode: input.settlementDescriptorValue?.outputBindingMode ?? "none",
1061
1214
  trust: bondPayload.trust,
1062
- trustSummary: {
1063
- definition: bondPayload.trust.definitionTrust,
1064
- issuance: bondPayload.trust.issuanceTrust,
1065
- bindingMode: input.settlementDescriptorValue?.outputBindingMode ?? "none",
1066
- },
1215
+ trustSummary: evidence.trustSummary,
1067
1216
  evidenceSummary: {
1068
1217
  definitionHash: evidence.definition.hash,
1069
1218
  issuanceHash: evidence.issuance.hash,
@@ -1,4 +1,4 @@
1
- import { BondDefinition, BondIssuanceState } from "../core/types";
1
+ import { BondDefinition, BondIssuanceState, BondIssuanceStatus } from "../core/types";
2
2
  export declare function summarizeBondIssuanceState(state: BondIssuanceState): {
3
3
  canonicalJson: string;
4
4
  hash: string;
@@ -33,3 +33,33 @@ export declare function buildClosedBondIssuanceState(input: {
33
33
  closingReason: "REDEEMED" | "CANCELLED" | "MATURED_OUT";
34
34
  finalSettlementDescriptorHash: string;
35
35
  }): BondIssuanceState;
36
+ export declare function verifyBondIssuanceHistory(input: {
37
+ history: BondIssuanceState[];
38
+ }): {
39
+ chainLength: number;
40
+ latestStatus: BondIssuanceStatus | undefined;
41
+ startsAtGenesis: boolean;
42
+ previousStateHashLinked: boolean;
43
+ issuanceIdConsistent: boolean;
44
+ bondIdConsistent: boolean;
45
+ currencyConsistent: boolean;
46
+ controllerConsistent: boolean;
47
+ issuerEntityConsistent: boolean;
48
+ issuedPrincipalConsistent: boolean;
49
+ allPreviousStateHashMatch: boolean;
50
+ allRedemptionArithmeticValid: boolean;
51
+ allStatusProgressionValid: boolean;
52
+ allTransitionIdentitiesMatch: boolean;
53
+ fullHistoryVerified: boolean;
54
+ transitionChecks: {
55
+ issuanceIdMatch: boolean;
56
+ bondIdMatch: boolean;
57
+ currencyMatch: boolean;
58
+ controllerMatch: boolean;
59
+ issuerEntityMatch: boolean;
60
+ issuedPrincipalMatch: boolean;
61
+ previousStateHashMatch: boolean;
62
+ redemptionArithmeticValid: boolean;
63
+ statusProgressionValid: boolean;
64
+ }[];
65
+ };