@plasius/economy 0.6.0 → 0.7.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 +23 -0
- package/dist/index.cjs +387 -36
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +94 -2
- package/dist/index.d.ts +94 -2
- package/dist/index.js +379 -36
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -100,6 +100,10 @@ __export(index_exports, {
|
|
|
100
100
|
assertModuleSpendQuote: () => assertModuleSpendQuote,
|
|
101
101
|
assertNonNegativeAccounts: () => assertNonNegativeAccounts,
|
|
102
102
|
assertOpenPurchaseIntent: () => assertOpenPurchaseIntent,
|
|
103
|
+
assertOperatorAdjustmentDecision: () => assertOperatorAdjustmentDecision,
|
|
104
|
+
assertOperatorAdjustmentExecution: () => assertOperatorAdjustmentExecution,
|
|
105
|
+
assertOperatorAdjustmentPreview: () => assertOperatorAdjustmentPreview,
|
|
106
|
+
assertOperatorAdjustmentProposal: () => assertOperatorAdjustmentProposal,
|
|
103
107
|
assertPaidLotLifecycle: () => assertPaidLotLifecycle,
|
|
104
108
|
assertPaidLotLifecycleEvent: () => assertPaidLotLifecycleEvent,
|
|
105
109
|
assertPaidLotPurchaseProvenance: () => assertPaidLotPurchaseProvenance,
|
|
@@ -163,6 +167,10 @@ __export(index_exports, {
|
|
|
163
167
|
canonicalEconomyRegionalEvidenceReceiptBodyPayload: () => canonicalEconomyRegionalEvidenceReceiptBodyPayload,
|
|
164
168
|
canonicalEconomyRegionalEvidenceReceiptPayload: () => canonicalEconomyRegionalEvidenceReceiptPayload,
|
|
165
169
|
canonicalEconomyRegionalEvidenceReceiptSigningPayload: () => canonicalEconomyRegionalEvidenceReceiptSigningPayload,
|
|
170
|
+
canonicalOperatorAdjustmentDecisionPayload: () => canonicalOperatorAdjustmentDecisionPayload,
|
|
171
|
+
canonicalOperatorAdjustmentExecutionPayload: () => canonicalOperatorAdjustmentExecutionPayload,
|
|
172
|
+
canonicalOperatorAdjustmentPreviewPayload: () => canonicalOperatorAdjustmentPreviewPayload,
|
|
173
|
+
canonicalOperatorAdjustmentProposalPayload: () => canonicalOperatorAdjustmentProposalPayload,
|
|
166
174
|
canonicalPersonalWalletInitializationCommandPayload: () => canonicalPersonalWalletInitializationCommandPayload,
|
|
167
175
|
canonicalPersonalWalletInitializationOutboxPayload: () => canonicalPersonalWalletInitializationOutboxPayload,
|
|
168
176
|
canonicalTransactionPayload: () => canonicalTransactionPayload,
|
|
@@ -4546,6 +4554,341 @@ function assertDistinctAdjustmentApproval(request) {
|
|
|
4546
4554
|
}
|
|
4547
4555
|
}
|
|
4548
4556
|
|
|
4557
|
+
// src/operator-adjustments.ts
|
|
4558
|
+
var PREVIEW_KEYS = /* @__PURE__ */ new Set([
|
|
4559
|
+
"schemaVersion",
|
|
4560
|
+
"previewId",
|
|
4561
|
+
"adjustmentId",
|
|
4562
|
+
"operation",
|
|
4563
|
+
"targetAccountId",
|
|
4564
|
+
"targetComponent",
|
|
4565
|
+
"targetWalletId",
|
|
4566
|
+
"targetLedgerAccountId",
|
|
4567
|
+
"offsetLedgerAccountId",
|
|
4568
|
+
"sourceLotId",
|
|
4569
|
+
"amount",
|
|
4570
|
+
"reasonCode",
|
|
4571
|
+
"ticketReferenceHash",
|
|
4572
|
+
"transferPolicy",
|
|
4573
|
+
"refundPolicy",
|
|
4574
|
+
"originalSourceLotId",
|
|
4575
|
+
"originalTransactionId",
|
|
4576
|
+
"preparedAt",
|
|
4577
|
+
"expiresAt"
|
|
4578
|
+
]);
|
|
4579
|
+
var DECISION_KEYS = /* @__PURE__ */ new Set([
|
|
4580
|
+
"schemaVersion",
|
|
4581
|
+
"decisionId",
|
|
4582
|
+
"adjustmentId",
|
|
4583
|
+
"proposalId",
|
|
4584
|
+
"proposalHash",
|
|
4585
|
+
"previewHash",
|
|
4586
|
+
"decision",
|
|
4587
|
+
"proposedByAccountId",
|
|
4588
|
+
"decidedByAccountId",
|
|
4589
|
+
"proposedAt",
|
|
4590
|
+
"decidedAt"
|
|
4591
|
+
]);
|
|
4592
|
+
var PROPOSAL_KEYS = /* @__PURE__ */ new Set([
|
|
4593
|
+
"schemaVersion",
|
|
4594
|
+
"proposalId",
|
|
4595
|
+
"adjustmentId",
|
|
4596
|
+
"previewHash",
|
|
4597
|
+
"status",
|
|
4598
|
+
"proposedByAccountId",
|
|
4599
|
+
"proposedAt",
|
|
4600
|
+
"expiresAt"
|
|
4601
|
+
]);
|
|
4602
|
+
var EXECUTION_KEYS = /* @__PURE__ */ new Set([
|
|
4603
|
+
"schemaVersion",
|
|
4604
|
+
"executionId",
|
|
4605
|
+
"adjustmentId",
|
|
4606
|
+
"previewHash",
|
|
4607
|
+
"proposalHash",
|
|
4608
|
+
"decisionHash",
|
|
4609
|
+
"sourceLotId",
|
|
4610
|
+
"transactionId",
|
|
4611
|
+
"resultReceiptId",
|
|
4612
|
+
"executedAt"
|
|
4613
|
+
]);
|
|
4614
|
+
var OPERATIONS = /* @__PURE__ */ new Set([
|
|
4615
|
+
"credit",
|
|
4616
|
+
"reverse-credit"
|
|
4617
|
+
]);
|
|
4618
|
+
var TARGET_COMPONENTS = /* @__PURE__ */ new Set([
|
|
4619
|
+
"personal",
|
|
4620
|
+
"household-treasury"
|
|
4621
|
+
]);
|
|
4622
|
+
var TRANSFER_POLICIES = /* @__PURE__ */ new Set([
|
|
4623
|
+
"household-allocatable",
|
|
4624
|
+
"same-user-only",
|
|
4625
|
+
"non-transferable"
|
|
4626
|
+
]);
|
|
4627
|
+
var DECISIONS = /* @__PURE__ */ new Set([
|
|
4628
|
+
"approve",
|
|
4629
|
+
"reject"
|
|
4630
|
+
]);
|
|
4631
|
+
function assertExactKeys3(value, allowed, label) {
|
|
4632
|
+
economyAssert(
|
|
4633
|
+
value !== null && typeof value === "object" && !Array.isArray(value),
|
|
4634
|
+
"INVALID_CONTRACT",
|
|
4635
|
+
`${label} must be an object`
|
|
4636
|
+
);
|
|
4637
|
+
economyAssert(
|
|
4638
|
+
Object.keys(value).every((key) => allowed.has(key)),
|
|
4639
|
+
"INVALID_CONTRACT",
|
|
4640
|
+
`${label} contains an unsupported field`
|
|
4641
|
+
);
|
|
4642
|
+
}
|
|
4643
|
+
function assertCanonicalHash6(value, label) {
|
|
4644
|
+
economyAssert(
|
|
4645
|
+
/^sha256:[a-f0-9]{64}$/u.test(value),
|
|
4646
|
+
"INVALID_CONTRACT",
|
|
4647
|
+
`${label} must be a canonical SHA-256 reference`
|
|
4648
|
+
);
|
|
4649
|
+
}
|
|
4650
|
+
function assertReasonCode(reasonCode) {
|
|
4651
|
+
economyAssert(
|
|
4652
|
+
/^[A-Z][A-Z0-9_]{2,95}$/u.test(reasonCode),
|
|
4653
|
+
"INVALID_CONTRACT",
|
|
4654
|
+
"Adjustment reasonCode must be a bounded uppercase identifier"
|
|
4655
|
+
);
|
|
4656
|
+
}
|
|
4657
|
+
function assertOperatorAdjustmentPreview(preview) {
|
|
4658
|
+
assertExactKeys3(preview, PREVIEW_KEYS, "Operator adjustment preview");
|
|
4659
|
+
economyAssert(
|
|
4660
|
+
preview.schemaVersion === ECONOMY_CONTRACT_VERSION && OPERATIONS.has(preview.operation) && TARGET_COMPONENTS.has(preview.targetComponent) && TRANSFER_POLICIES.has(preview.transferPolicy) && preview.refundPolicy === "not-refundable",
|
|
4661
|
+
"INVALID_CONTRACT",
|
|
4662
|
+
"Unsupported operator adjustment preview"
|
|
4663
|
+
);
|
|
4664
|
+
assertEconomyIdentifier(preview.previewId, "previewId");
|
|
4665
|
+
assertEconomyIdentifier(preview.adjustmentId, "adjustmentId");
|
|
4666
|
+
assertEconomyIdentifier(preview.targetAccountId, "targetAccountId");
|
|
4667
|
+
assertEconomyIdentifier(preview.targetWalletId, "targetWalletId");
|
|
4668
|
+
assertEconomyIdentifier(
|
|
4669
|
+
preview.targetLedgerAccountId,
|
|
4670
|
+
"targetLedgerAccountId"
|
|
4671
|
+
);
|
|
4672
|
+
assertEconomyIdentifier(
|
|
4673
|
+
preview.offsetLedgerAccountId,
|
|
4674
|
+
"offsetLedgerAccountId"
|
|
4675
|
+
);
|
|
4676
|
+
assertEconomyIdentifier(preview.sourceLotId, "sourceLotId");
|
|
4677
|
+
economyAssert(
|
|
4678
|
+
parseTokenSubunits(preview.amount) > 0n,
|
|
4679
|
+
"INVALID_AMOUNT",
|
|
4680
|
+
"Operator adjustment amount must be positive"
|
|
4681
|
+
);
|
|
4682
|
+
assertReasonCode(preview.reasonCode);
|
|
4683
|
+
assertCanonicalHash6(preview.ticketReferenceHash, "ticketReferenceHash");
|
|
4684
|
+
const preparedAt = parseIsoTimestamp(preview.preparedAt);
|
|
4685
|
+
const expiresAt = parseIsoTimestamp(preview.expiresAt);
|
|
4686
|
+
economyAssert(
|
|
4687
|
+
expiresAt > preparedAt,
|
|
4688
|
+
"INVALID_TIME_WINDOW",
|
|
4689
|
+
"Operator adjustment preview must expire after preparation"
|
|
4690
|
+
);
|
|
4691
|
+
if (preview.operation === "credit") {
|
|
4692
|
+
economyAssert(
|
|
4693
|
+
preview.originalSourceLotId === void 0 && preview.originalTransactionId === void 0,
|
|
4694
|
+
"INVALID_CONTRACT",
|
|
4695
|
+
"A credit preview cannot bind an original transaction"
|
|
4696
|
+
);
|
|
4697
|
+
return;
|
|
4698
|
+
}
|
|
4699
|
+
economyAssert(
|
|
4700
|
+
preview.originalSourceLotId !== void 0 && preview.originalTransactionId !== void 0,
|
|
4701
|
+
"INVALID_CONTRACT",
|
|
4702
|
+
"A reversal preview must bind the original lot and transaction"
|
|
4703
|
+
);
|
|
4704
|
+
assertEconomyIdentifier(preview.originalSourceLotId, "originalSourceLotId");
|
|
4705
|
+
assertEconomyIdentifier(
|
|
4706
|
+
preview.originalTransactionId,
|
|
4707
|
+
"originalTransactionId"
|
|
4708
|
+
);
|
|
4709
|
+
}
|
|
4710
|
+
function canonicalOperatorAdjustmentPreviewPayload(preview) {
|
|
4711
|
+
assertOperatorAdjustmentPreview(preview);
|
|
4712
|
+
return JSON.stringify({
|
|
4713
|
+
schemaVersion: preview.schemaVersion,
|
|
4714
|
+
previewId: preview.previewId,
|
|
4715
|
+
adjustmentId: preview.adjustmentId,
|
|
4716
|
+
operation: preview.operation,
|
|
4717
|
+
targetAccountId: preview.targetAccountId,
|
|
4718
|
+
targetComponent: preview.targetComponent,
|
|
4719
|
+
targetWalletId: preview.targetWalletId,
|
|
4720
|
+
targetLedgerAccountId: preview.targetLedgerAccountId,
|
|
4721
|
+
offsetLedgerAccountId: preview.offsetLedgerAccountId,
|
|
4722
|
+
sourceLotId: preview.sourceLotId,
|
|
4723
|
+
amount: preview.amount,
|
|
4724
|
+
reasonCode: preview.reasonCode,
|
|
4725
|
+
ticketReferenceHash: preview.ticketReferenceHash,
|
|
4726
|
+
transferPolicy: preview.transferPolicy,
|
|
4727
|
+
refundPolicy: preview.refundPolicy,
|
|
4728
|
+
...preview.originalSourceLotId === void 0 ? {} : { originalSourceLotId: preview.originalSourceLotId },
|
|
4729
|
+
...preview.originalTransactionId === void 0 ? {} : { originalTransactionId: preview.originalTransactionId },
|
|
4730
|
+
preparedAt: preview.preparedAt,
|
|
4731
|
+
expiresAt: preview.expiresAt
|
|
4732
|
+
});
|
|
4733
|
+
}
|
|
4734
|
+
function assertOperatorAdjustmentProposal(proposal, preview, expectedPreviewHash) {
|
|
4735
|
+
assertOperatorAdjustmentPreview(preview);
|
|
4736
|
+
assertCanonicalHash6(expectedPreviewHash, "expectedPreviewHash");
|
|
4737
|
+
assertExactKeys3(proposal, PROPOSAL_KEYS, "Operator adjustment proposal");
|
|
4738
|
+
economyAssert(
|
|
4739
|
+
proposal.schemaVersion === ECONOMY_CONTRACT_VERSION && proposal.status === "pending-approval",
|
|
4740
|
+
"INVALID_CONTRACT",
|
|
4741
|
+
"Unsupported operator adjustment proposal"
|
|
4742
|
+
);
|
|
4743
|
+
assertEconomyIdentifier(proposal.proposalId, "proposalId");
|
|
4744
|
+
assertEconomyIdentifier(proposal.adjustmentId, "adjustmentId");
|
|
4745
|
+
assertCanonicalHash6(proposal.previewHash, "previewHash");
|
|
4746
|
+
assertEconomyIdentifier(
|
|
4747
|
+
proposal.proposedByAccountId,
|
|
4748
|
+
"proposedByAccountId"
|
|
4749
|
+
);
|
|
4750
|
+
economyAssert(
|
|
4751
|
+
proposal.adjustmentId === preview.adjustmentId && proposal.previewHash === expectedPreviewHash,
|
|
4752
|
+
"ADJUSTMENT_PREVIEW_MISMATCH",
|
|
4753
|
+
"Operator adjustment proposal does not match its preview"
|
|
4754
|
+
);
|
|
4755
|
+
const proposedAt = parseIsoTimestamp(proposal.proposedAt);
|
|
4756
|
+
const expiresAt = parseIsoTimestamp(proposal.expiresAt);
|
|
4757
|
+
economyAssert(
|
|
4758
|
+
proposedAt >= parseIsoTimestamp(preview.preparedAt) && expiresAt === parseIsoTimestamp(preview.expiresAt) && expiresAt > proposedAt,
|
|
4759
|
+
"INVALID_TIME_WINDOW",
|
|
4760
|
+
"Operator adjustment proposal times are inconsistent"
|
|
4761
|
+
);
|
|
4762
|
+
}
|
|
4763
|
+
function canonicalOperatorAdjustmentProposalPayload(proposal) {
|
|
4764
|
+
assertExactKeys3(proposal, PROPOSAL_KEYS, "Operator adjustment proposal");
|
|
4765
|
+
return JSON.stringify({
|
|
4766
|
+
schemaVersion: proposal.schemaVersion,
|
|
4767
|
+
proposalId: proposal.proposalId,
|
|
4768
|
+
adjustmentId: proposal.adjustmentId,
|
|
4769
|
+
previewHash: proposal.previewHash,
|
|
4770
|
+
status: proposal.status,
|
|
4771
|
+
proposedByAccountId: proposal.proposedByAccountId,
|
|
4772
|
+
proposedAt: proposal.proposedAt,
|
|
4773
|
+
expiresAt: proposal.expiresAt
|
|
4774
|
+
});
|
|
4775
|
+
}
|
|
4776
|
+
function assertOperatorAdjustmentDecision(decision, proposal, preview, expectedPreviewHash, expectedProposalHash) {
|
|
4777
|
+
assertOperatorAdjustmentProposal(proposal, preview, expectedPreviewHash);
|
|
4778
|
+
assertCanonicalHash6(expectedProposalHash, "expectedProposalHash");
|
|
4779
|
+
assertExactKeys3(decision, DECISION_KEYS, "Operator adjustment decision");
|
|
4780
|
+
economyAssert(
|
|
4781
|
+
decision.schemaVersion === ECONOMY_CONTRACT_VERSION && DECISIONS.has(decision.decision),
|
|
4782
|
+
"INVALID_CONTRACT",
|
|
4783
|
+
"Unsupported operator adjustment decision"
|
|
4784
|
+
);
|
|
4785
|
+
assertEconomyIdentifier(decision.decisionId, "decisionId");
|
|
4786
|
+
assertEconomyIdentifier(decision.adjustmentId, "adjustmentId");
|
|
4787
|
+
assertEconomyIdentifier(decision.proposalId, "proposalId");
|
|
4788
|
+
assertCanonicalHash6(decision.proposalHash, "proposalHash");
|
|
4789
|
+
assertCanonicalHash6(decision.previewHash, "previewHash");
|
|
4790
|
+
assertEconomyIdentifier(
|
|
4791
|
+
decision.proposedByAccountId,
|
|
4792
|
+
"proposedByAccountId"
|
|
4793
|
+
);
|
|
4794
|
+
assertEconomyIdentifier(
|
|
4795
|
+
decision.decidedByAccountId,
|
|
4796
|
+
"decidedByAccountId"
|
|
4797
|
+
);
|
|
4798
|
+
economyAssert(
|
|
4799
|
+
decision.proposedByAccountId !== decision.decidedByAccountId,
|
|
4800
|
+
"ADJUSTMENT_SELF_APPROVAL",
|
|
4801
|
+
"Operator adjustment approval requires a distinct operator"
|
|
4802
|
+
);
|
|
4803
|
+
economyAssert(
|
|
4804
|
+
decision.adjustmentId === preview.adjustmentId && decision.proposalId === proposal.proposalId && decision.proposalHash === expectedProposalHash && decision.previewHash === expectedPreviewHash,
|
|
4805
|
+
"ADJUSTMENT_PREVIEW_MISMATCH",
|
|
4806
|
+
"Operator adjustment decision does not match its preview"
|
|
4807
|
+
);
|
|
4808
|
+
const proposedAt = parseIsoTimestamp(decision.proposedAt);
|
|
4809
|
+
const decidedAt = parseIsoTimestamp(decision.decidedAt);
|
|
4810
|
+
economyAssert(
|
|
4811
|
+
decision.proposedByAccountId === proposal.proposedByAccountId && proposedAt === parseIsoTimestamp(proposal.proposedAt) && decidedAt >= proposedAt,
|
|
4812
|
+
"INVALID_TIME_WINDOW",
|
|
4813
|
+
"Operator adjustment decision times are inconsistent"
|
|
4814
|
+
);
|
|
4815
|
+
economyAssert(
|
|
4816
|
+
decidedAt <= parseIsoTimestamp(preview.expiresAt),
|
|
4817
|
+
"ADJUSTMENT_EXPIRED",
|
|
4818
|
+
"Operator adjustment preview has expired"
|
|
4819
|
+
);
|
|
4820
|
+
}
|
|
4821
|
+
function canonicalOperatorAdjustmentDecisionPayload(decision) {
|
|
4822
|
+
assertExactKeys3(decision, DECISION_KEYS, "Operator adjustment decision");
|
|
4823
|
+
return JSON.stringify({
|
|
4824
|
+
schemaVersion: decision.schemaVersion,
|
|
4825
|
+
decisionId: decision.decisionId,
|
|
4826
|
+
adjustmentId: decision.adjustmentId,
|
|
4827
|
+
proposalId: decision.proposalId,
|
|
4828
|
+
proposalHash: decision.proposalHash,
|
|
4829
|
+
previewHash: decision.previewHash,
|
|
4830
|
+
decision: decision.decision,
|
|
4831
|
+
proposedByAccountId: decision.proposedByAccountId,
|
|
4832
|
+
decidedByAccountId: decision.decidedByAccountId,
|
|
4833
|
+
proposedAt: decision.proposedAt,
|
|
4834
|
+
decidedAt: decision.decidedAt
|
|
4835
|
+
});
|
|
4836
|
+
}
|
|
4837
|
+
function assertOperatorAdjustmentExecution(execution, preview, proposal, decision, expectedPreviewHash, expectedProposalHash, expectedDecisionHash) {
|
|
4838
|
+
assertOperatorAdjustmentDecision(
|
|
4839
|
+
decision,
|
|
4840
|
+
proposal,
|
|
4841
|
+
preview,
|
|
4842
|
+
expectedPreviewHash,
|
|
4843
|
+
expectedProposalHash
|
|
4844
|
+
);
|
|
4845
|
+
assertCanonicalHash6(expectedDecisionHash, "expectedDecisionHash");
|
|
4846
|
+
assertExactKeys3(execution, EXECUTION_KEYS, "Operator adjustment execution");
|
|
4847
|
+
economyAssert(
|
|
4848
|
+
execution.schemaVersion === ECONOMY_CONTRACT_VERSION,
|
|
4849
|
+
"INVALID_CONTRACT",
|
|
4850
|
+
"Unsupported operator adjustment execution"
|
|
4851
|
+
);
|
|
4852
|
+
assertEconomyIdentifier(execution.executionId, "executionId");
|
|
4853
|
+
assertEconomyIdentifier(execution.adjustmentId, "adjustmentId");
|
|
4854
|
+
assertCanonicalHash6(execution.previewHash, "previewHash");
|
|
4855
|
+
assertCanonicalHash6(execution.proposalHash, "proposalHash");
|
|
4856
|
+
assertCanonicalHash6(execution.decisionHash, "decisionHash");
|
|
4857
|
+
assertEconomyIdentifier(execution.sourceLotId, "sourceLotId");
|
|
4858
|
+
assertEconomyIdentifier(execution.transactionId, "transactionId");
|
|
4859
|
+
assertEconomyIdentifier(execution.resultReceiptId, "resultReceiptId");
|
|
4860
|
+
economyAssert(
|
|
4861
|
+
decision.decision === "approve",
|
|
4862
|
+
"ADJUSTMENT_NOT_APPROVED",
|
|
4863
|
+
"Only an approved adjustment may execute"
|
|
4864
|
+
);
|
|
4865
|
+
economyAssert(
|
|
4866
|
+
execution.adjustmentId === preview.adjustmentId && execution.previewHash === expectedPreviewHash && execution.proposalHash === expectedProposalHash && execution.decisionHash === expectedDecisionHash && execution.sourceLotId === preview.sourceLotId,
|
|
4867
|
+
"ADJUSTMENT_PREVIEW_MISMATCH",
|
|
4868
|
+
"Operator adjustment execution does not match its approval plan"
|
|
4869
|
+
);
|
|
4870
|
+
economyAssert(
|
|
4871
|
+
parseIsoTimestamp(execution.executedAt) >= parseIsoTimestamp(decision.decidedAt),
|
|
4872
|
+
"INVALID_TIME_WINDOW",
|
|
4873
|
+
"Operator adjustment execution predates its decision"
|
|
4874
|
+
);
|
|
4875
|
+
}
|
|
4876
|
+
function canonicalOperatorAdjustmentExecutionPayload(execution) {
|
|
4877
|
+
assertExactKeys3(execution, EXECUTION_KEYS, "Operator adjustment execution");
|
|
4878
|
+
return JSON.stringify({
|
|
4879
|
+
schemaVersion: execution.schemaVersion,
|
|
4880
|
+
executionId: execution.executionId,
|
|
4881
|
+
adjustmentId: execution.adjustmentId,
|
|
4882
|
+
previewHash: execution.previewHash,
|
|
4883
|
+
proposalHash: execution.proposalHash,
|
|
4884
|
+
decisionHash: execution.decisionHash,
|
|
4885
|
+
sourceLotId: execution.sourceLotId,
|
|
4886
|
+
transactionId: execution.transactionId,
|
|
4887
|
+
resultReceiptId: execution.resultReceiptId,
|
|
4888
|
+
executedAt: execution.executedAt
|
|
4889
|
+
});
|
|
4890
|
+
}
|
|
4891
|
+
|
|
4549
4892
|
// src/paid-lots.ts
|
|
4550
4893
|
var ZERO_ARITHMETIC = Object.freeze({
|
|
4551
4894
|
retainedDelta: serializeTokenSubunits(0n),
|
|
@@ -7086,7 +7429,7 @@ var PORTABLE_KEYS = /* @__PURE__ */ new Set([
|
|
|
7086
7429
|
"signature",
|
|
7087
7430
|
...PORTABLE_BODY_KEYS
|
|
7088
7431
|
]);
|
|
7089
|
-
function
|
|
7432
|
+
function assertExactKeys4(value, allowedKeys, label) {
|
|
7090
7433
|
economyAssert(
|
|
7091
7434
|
value !== null && typeof value === "object" && !Array.isArray(value),
|
|
7092
7435
|
"INVALID_CONTRACT",
|
|
@@ -7098,7 +7441,7 @@ function assertExactKeys3(value, allowedKeys, label) {
|
|
|
7098
7441
|
`${label} contains an unsupported field`
|
|
7099
7442
|
);
|
|
7100
7443
|
}
|
|
7101
|
-
function
|
|
7444
|
+
function assertCanonicalHash7(value, label) {
|
|
7102
7445
|
economyAssert(
|
|
7103
7446
|
typeof value === "string" && CANONICAL_HASH.test(value),
|
|
7104
7447
|
"INVALID_CONTRACT",
|
|
@@ -7107,7 +7450,7 @@ function assertCanonicalHash6(value, label) {
|
|
|
7107
7450
|
}
|
|
7108
7451
|
function canonicalHash(payload, hashCanonicalPayload2, label) {
|
|
7109
7452
|
const value = hashCanonicalPayload2(payload);
|
|
7110
|
-
|
|
7453
|
+
assertCanonicalHash7(value, label);
|
|
7111
7454
|
return value;
|
|
7112
7455
|
}
|
|
7113
7456
|
function assertUnsignedInteger(value, label) {
|
|
@@ -7175,7 +7518,7 @@ function canonicalSignatureMetadata(signature) {
|
|
|
7175
7518
|
};
|
|
7176
7519
|
}
|
|
7177
7520
|
function assertEconomySealedRecoveryPayload(payload) {
|
|
7178
|
-
|
|
7521
|
+
assertExactKeys4(
|
|
7179
7522
|
payload,
|
|
7180
7523
|
/* @__PURE__ */ new Set([
|
|
7181
7524
|
"schemaVersion",
|
|
@@ -7205,17 +7548,17 @@ function assertEconomySealedRecoveryPayload(payload) {
|
|
|
7205
7548
|
22,
|
|
7206
7549
|
22
|
|
7207
7550
|
);
|
|
7208
|
-
|
|
7551
|
+
assertCanonicalHash7(
|
|
7209
7552
|
payload.plaintextContentHash,
|
|
7210
7553
|
"Recovery plaintext-content hash"
|
|
7211
7554
|
);
|
|
7212
|
-
|
|
7555
|
+
assertCanonicalHash7(
|
|
7213
7556
|
payload.encryptionContextHash,
|
|
7214
7557
|
"Recovery encryption-context hash"
|
|
7215
7558
|
);
|
|
7216
7559
|
}
|
|
7217
7560
|
function assertAcceptanceBody(body) {
|
|
7218
|
-
|
|
7561
|
+
assertExactKeys4(
|
|
7219
7562
|
body,
|
|
7220
7563
|
"acceptanceEnvelopeId" in body ? ACCEPTANCE_KEYS : ACCEPTANCE_BODY_KEYS,
|
|
7221
7564
|
"Recovery acceptance body"
|
|
@@ -7234,9 +7577,9 @@ function assertAcceptanceBody(body) {
|
|
|
7234
7577
|
body.idempotencyFingerprint,
|
|
7235
7578
|
"economy.idempotency-key.v1"
|
|
7236
7579
|
);
|
|
7237
|
-
|
|
7580
|
+
assertCanonicalHash7(body.commandEnvelopeHash, "Command-envelope hash");
|
|
7238
7581
|
assertEconomyIdentifier(body.acceptedReceiptId, "acceptedReceiptId");
|
|
7239
|
-
|
|
7582
|
+
assertCanonicalHash7(body.acceptedReceiptHash, "Accepted-receipt hash");
|
|
7240
7583
|
assertEconomySealedRecoveryPayload(body.sealedPayload);
|
|
7241
7584
|
const preparedAt = parseIsoTimestamp(body.preparedAt);
|
|
7242
7585
|
const acceptedAt = parseIsoTimestamp(body.acceptedAt);
|
|
@@ -7284,7 +7627,7 @@ function createEconomyRecoveryAcceptanceEnvelope(body, hashCanonicalPayload2) {
|
|
|
7284
7627
|
};
|
|
7285
7628
|
}
|
|
7286
7629
|
function assertEconomyRecoveryAcceptanceEnvelope(envelope, hashCanonicalPayload2) {
|
|
7287
|
-
|
|
7630
|
+
assertExactKeys4(envelope, ACCEPTANCE_KEYS, "Recovery acceptance envelope");
|
|
7288
7631
|
assertAcceptanceBody(envelope);
|
|
7289
7632
|
assertEconomyIdentifier(
|
|
7290
7633
|
envelope.acceptanceEnvelopeId,
|
|
@@ -7325,7 +7668,7 @@ function canonicalEconomyRecoveryAcceptanceEnvelopePayload(envelope, hashCanonic
|
|
|
7325
7668
|
});
|
|
7326
7669
|
}
|
|
7327
7670
|
function assertCommittedResultBody(body) {
|
|
7328
|
-
|
|
7671
|
+
assertExactKeys4(
|
|
7329
7672
|
body,
|
|
7330
7673
|
"committedResultId" in body ? COMMITTED_RESULT_KEYS : COMMITTED_RESULT_BODY_KEYS,
|
|
7331
7674
|
"Recovery committed-result body"
|
|
@@ -7353,7 +7696,7 @@ function assertCommittedResultBody(body) {
|
|
|
7353
7696
|
[body.authorityCommitHash, "Authority-commit hash"],
|
|
7354
7697
|
[body.authorityHeadHashAfter, "Authority-head hash"]
|
|
7355
7698
|
]) {
|
|
7356
|
-
|
|
7699
|
+
assertCanonicalHash7(value, label);
|
|
7357
7700
|
}
|
|
7358
7701
|
economyAssert(
|
|
7359
7702
|
RESULT_OUTCOMES.has(body.outcome),
|
|
@@ -7376,7 +7719,7 @@ function assertCommittedResultBody(body) {
|
|
|
7376
7719
|
assertEconomyIdentifier(body.transactionId, "transactionId");
|
|
7377
7720
|
}
|
|
7378
7721
|
if (body.transactionCanonicalHash !== void 0) {
|
|
7379
|
-
|
|
7722
|
+
assertCanonicalHash7(
|
|
7380
7723
|
body.transactionCanonicalHash,
|
|
7381
7724
|
"Transaction canonical hash"
|
|
7382
7725
|
);
|
|
@@ -7419,7 +7762,7 @@ function createEconomyRecoveryCommittedResult(body, hashCanonicalPayload2) {
|
|
|
7419
7762
|
};
|
|
7420
7763
|
}
|
|
7421
7764
|
function assertEconomyRecoveryCommittedResult(result, hashCanonicalPayload2) {
|
|
7422
|
-
|
|
7765
|
+
assertExactKeys4(
|
|
7423
7766
|
result,
|
|
7424
7767
|
COMMITTED_RESULT_KEYS,
|
|
7425
7768
|
"Recovery committed result"
|
|
@@ -7478,7 +7821,7 @@ function assertEconomyRecoveryResultLink(acceptance, result, hashCanonicalPayloa
|
|
|
7478
7821
|
);
|
|
7479
7822
|
}
|
|
7480
7823
|
function assertEconomyEvidenceSignatureMetadata(signature) {
|
|
7481
|
-
|
|
7824
|
+
assertExactKeys4(
|
|
7482
7825
|
signature,
|
|
7483
7826
|
/* @__PURE__ */ new Set([
|
|
7484
7827
|
"schemaVersion",
|
|
@@ -7498,7 +7841,7 @@ function assertEconomyEvidenceSignatureMetadata(signature) {
|
|
|
7498
7841
|
parseIsoTimestamp(signature.signedAt);
|
|
7499
7842
|
}
|
|
7500
7843
|
function assertEconomyEvidenceSignature(signature) {
|
|
7501
|
-
|
|
7844
|
+
assertExactKeys4(
|
|
7502
7845
|
signature,
|
|
7503
7846
|
/* @__PURE__ */ new Set([
|
|
7504
7847
|
"schemaVersion",
|
|
@@ -7520,7 +7863,7 @@ function assertEconomyEvidenceSignature(signature) {
|
|
|
7520
7863
|
assertBase64url(signature.value, "Evidence signature value", 32, 2048);
|
|
7521
7864
|
}
|
|
7522
7865
|
function assertRegionalEvidenceBody(body) {
|
|
7523
|
-
|
|
7866
|
+
assertExactKeys4(
|
|
7524
7867
|
body,
|
|
7525
7868
|
"evidenceReceiptId" in body ? REGIONAL_KEYS : REGIONAL_BODY_KEYS,
|
|
7526
7869
|
"Regional evidence-receipt body"
|
|
@@ -7552,7 +7895,7 @@ function assertRegionalEvidenceBody(body) {
|
|
|
7552
7895
|
"INVALID_CONTRACT",
|
|
7553
7896
|
"Unsupported recovery record kind"
|
|
7554
7897
|
);
|
|
7555
|
-
|
|
7898
|
+
assertCanonicalHash7(
|
|
7556
7899
|
body.recoveryRecordContentHash,
|
|
7557
7900
|
"Recovery-record content hash"
|
|
7558
7901
|
);
|
|
@@ -7568,7 +7911,7 @@ function assertRegionalEvidenceBody(body) {
|
|
|
7568
7911
|
"INVALID_CONTRACT",
|
|
7569
7912
|
"Non-genesis regional evidence receipt requires a previous hash"
|
|
7570
7913
|
);
|
|
7571
|
-
|
|
7914
|
+
assertCanonicalHash7(
|
|
7572
7915
|
body.previousReceiptHash,
|
|
7573
7916
|
"Previous evidence-receipt hash"
|
|
7574
7917
|
);
|
|
@@ -7612,7 +7955,7 @@ function createEconomyRegionalEvidenceReceipt(body, signature, hashCanonicalPayl
|
|
|
7612
7955
|
};
|
|
7613
7956
|
}
|
|
7614
7957
|
function assertEconomyRegionalEvidenceReceipt(receipt, hashCanonicalPayload2) {
|
|
7615
|
-
|
|
7958
|
+
assertExactKeys4(receipt, REGIONAL_KEYS, "Regional evidence receipt");
|
|
7616
7959
|
assertRegionalEvidenceBody(receipt);
|
|
7617
7960
|
assertEconomyIdentifier(receipt.evidenceReceiptId, "evidenceReceiptId");
|
|
7618
7961
|
assertEconomyEvidenceSignature(receipt.signature);
|
|
@@ -7743,7 +8086,7 @@ function assertEconomyRegionalEvidenceChain(receipts, expectedPreviousReceiptHas
|
|
|
7743
8086
|
"INVALID_CONTRACT",
|
|
7744
8087
|
"Partial evidence chain requires its trusted preceding hash"
|
|
7745
8088
|
);
|
|
7746
|
-
|
|
8089
|
+
assertCanonicalHash7(
|
|
7747
8090
|
expectedPreviousReceiptHash,
|
|
7748
8091
|
"Expected preceding evidence-receipt hash"
|
|
7749
8092
|
);
|
|
@@ -7814,7 +8157,7 @@ function assertEconomyRegionalEvidenceEquality(receipts, expectedRegions, hashCa
|
|
|
7814
8157
|
);
|
|
7815
8158
|
}
|
|
7816
8159
|
function assertEconomyMerkleInclusionProof(proof) {
|
|
7817
|
-
|
|
8160
|
+
assertExactKeys4(
|
|
7818
8161
|
proof,
|
|
7819
8162
|
/* @__PURE__ */ new Set([
|
|
7820
8163
|
"schemaVersion",
|
|
@@ -7835,8 +8178,8 @@ function assertEconomyMerkleInclusionProof(proof) {
|
|
|
7835
8178
|
"Unsupported Merkle inclusion proof"
|
|
7836
8179
|
);
|
|
7837
8180
|
assertEconomyIdentifier(proof.anchorId, "anchorId");
|
|
7838
|
-
|
|
7839
|
-
|
|
8181
|
+
assertCanonicalHash7(proof.anchorManifestHash, "Anchor-manifest hash");
|
|
8182
|
+
assertCanonicalHash7(proof.leafHash, "Merkle leaf hash");
|
|
7840
8183
|
assertUnsignedInteger(proof.leafIndex, "Merkle leaf index");
|
|
7841
8184
|
assertUnsignedInteger(proof.leafCount, "Merkle leaf count");
|
|
7842
8185
|
economyAssert(
|
|
@@ -7845,7 +8188,7 @@ function assertEconomyMerkleInclusionProof(proof) {
|
|
|
7845
8188
|
"Merkle leaf position is outside its bounded tree"
|
|
7846
8189
|
);
|
|
7847
8190
|
for (const step of proof.siblings) {
|
|
7848
|
-
|
|
8191
|
+
assertExactKeys4(
|
|
7849
8192
|
step,
|
|
7850
8193
|
/* @__PURE__ */ new Set(["schemaVersion", "side", "hash"]),
|
|
7851
8194
|
"Merkle proof step"
|
|
@@ -7855,7 +8198,7 @@ function assertEconomyMerkleInclusionProof(proof) {
|
|
|
7855
8198
|
"INVALID_CONTRACT",
|
|
7856
8199
|
"Unsupported Merkle proof step"
|
|
7857
8200
|
);
|
|
7858
|
-
|
|
8201
|
+
assertCanonicalHash7(step.hash, "Merkle sibling hash");
|
|
7859
8202
|
}
|
|
7860
8203
|
}
|
|
7861
8204
|
function canonicalMerkleProof(proof) {
|
|
@@ -7934,7 +8277,7 @@ function assertEconomyMerkleInclusion(proof, anchor, hashCanonicalPayload2) {
|
|
|
7934
8277
|
);
|
|
7935
8278
|
}
|
|
7936
8279
|
function assertPortableEvidenceReference(reference) {
|
|
7937
|
-
|
|
8280
|
+
assertExactKeys4(
|
|
7938
8281
|
reference,
|
|
7939
8282
|
/* @__PURE__ */ new Set([
|
|
7940
8283
|
"schemaVersion",
|
|
@@ -7954,7 +8297,7 @@ function assertPortableEvidenceReference(reference) {
|
|
|
7954
8297
|
reference.evidenceReceiptId,
|
|
7955
8298
|
"evidenceReceiptId"
|
|
7956
8299
|
);
|
|
7957
|
-
|
|
8300
|
+
assertCanonicalHash7(
|
|
7958
8301
|
reference.evidenceReceiptHash,
|
|
7959
8302
|
"Evidence-receipt hash"
|
|
7960
8303
|
);
|
|
@@ -7971,7 +8314,7 @@ function canonicalPortableEvidenceReference(reference) {
|
|
|
7971
8314
|
};
|
|
7972
8315
|
}
|
|
7973
8316
|
function assertPortableBody(body) {
|
|
7974
|
-
|
|
8317
|
+
assertExactKeys4(
|
|
7975
8318
|
body,
|
|
7976
8319
|
"portableReceiptId" in body ? PORTABLE_KEYS : PORTABLE_BODY_KEYS,
|
|
7977
8320
|
"Portable customer-receipt body"
|
|
@@ -8010,7 +8353,7 @@ function assertPortableBody(body) {
|
|
|
8010
8353
|
[body.committedResultContentHash, "Committed-result content hash"],
|
|
8011
8354
|
[body.authorityCommitHash, "Authority-commit hash"]
|
|
8012
8355
|
]) {
|
|
8013
|
-
|
|
8356
|
+
assertCanonicalHash7(value, label);
|
|
8014
8357
|
}
|
|
8015
8358
|
assertUnsignedInteger(body.authoritySequence, "Authority sequence");
|
|
8016
8359
|
economyAssert(
|
|
@@ -8095,7 +8438,7 @@ function createEconomyPortableCustomerReceipt(body, signature, hashCanonicalPayl
|
|
|
8095
8438
|
};
|
|
8096
8439
|
}
|
|
8097
8440
|
function assertEconomyPortableCustomerReceipt(receipt, hashCanonicalPayload2) {
|
|
8098
|
-
|
|
8441
|
+
assertExactKeys4(receipt, PORTABLE_KEYS, "Portable customer receipt");
|
|
8099
8442
|
assertPortableBody(receipt);
|
|
8100
8443
|
assertEconomyIdentifier(receipt.portableReceiptId, "portableReceiptId");
|
|
8101
8444
|
assertEconomyEvidenceSignature(receipt.signature);
|
|
@@ -8395,7 +8738,7 @@ var DOCUMENT_ID_KEYS = /* @__PURE__ */ new Set([
|
|
|
8395
8738
|
"lifetimeProjectionId",
|
|
8396
8739
|
"outboxEventId"
|
|
8397
8740
|
]);
|
|
8398
|
-
function
|
|
8741
|
+
function assertExactKeys5(value, allowed, label) {
|
|
8399
8742
|
economyAssert(
|
|
8400
8743
|
value !== null && typeof value === "object" && !Array.isArray(value),
|
|
8401
8744
|
"INVALID_CONTRACT",
|
|
@@ -8435,7 +8778,7 @@ function createPersonalWalletInitializationDocumentIds(subjectAccountId, hash) {
|
|
|
8435
8778
|
};
|
|
8436
8779
|
}
|
|
8437
8780
|
function assertPersonalWalletInitializationCommand(command) {
|
|
8438
|
-
|
|
8781
|
+
assertExactKeys5(command, COMMAND_KEYS, "Wallet initialization command");
|
|
8439
8782
|
economyAssert(
|
|
8440
8783
|
command.schemaVersion === ECONOMY_CONTRACT_VERSION && command.commandType === "initialize-wallet" && command.walletKind === "personal",
|
|
8441
8784
|
"INVALID_CONTRACT",
|
|
@@ -8459,7 +8802,7 @@ function canonicalPersonalWalletInitializationCommandPayload(command) {
|
|
|
8459
8802
|
});
|
|
8460
8803
|
}
|
|
8461
8804
|
function assertPersonalWalletInitializationOutboxIntent(intent) {
|
|
8462
|
-
|
|
8805
|
+
assertExactKeys5(intent, OUTBOX_KEYS, "Wallet initialization outbox intent");
|
|
8463
8806
|
economyAssert(
|
|
8464
8807
|
intent.schemaVersion === ECONOMY_CONTRACT_VERSION && intent.eventType === "wallet.initialized.v1",
|
|
8465
8808
|
"INVALID_CONTRACT",
|
|
@@ -8559,8 +8902,8 @@ function createPersonalWalletInitializationState(input, hash) {
|
|
|
8559
8902
|
return state;
|
|
8560
8903
|
}
|
|
8561
8904
|
function assertPersonalWalletInitializationState(state) {
|
|
8562
|
-
|
|
8563
|
-
|
|
8905
|
+
assertExactKeys5(state, STATE_KEYS, "Wallet initialization state");
|
|
8906
|
+
assertExactKeys5(
|
|
8564
8907
|
state.documentIds,
|
|
8565
8908
|
DOCUMENT_ID_KEYS,
|
|
8566
8909
|
"Wallet initialization document IDs"
|
|
@@ -8672,6 +9015,10 @@ function assertPersonalWalletInitializationState(state) {
|
|
|
8672
9015
|
assertModuleSpendQuote,
|
|
8673
9016
|
assertNonNegativeAccounts,
|
|
8674
9017
|
assertOpenPurchaseIntent,
|
|
9018
|
+
assertOperatorAdjustmentDecision,
|
|
9019
|
+
assertOperatorAdjustmentExecution,
|
|
9020
|
+
assertOperatorAdjustmentPreview,
|
|
9021
|
+
assertOperatorAdjustmentProposal,
|
|
8675
9022
|
assertPaidLotLifecycle,
|
|
8676
9023
|
assertPaidLotLifecycleEvent,
|
|
8677
9024
|
assertPaidLotPurchaseProvenance,
|
|
@@ -8735,6 +9082,10 @@ function assertPersonalWalletInitializationState(state) {
|
|
|
8735
9082
|
canonicalEconomyRegionalEvidenceReceiptBodyPayload,
|
|
8736
9083
|
canonicalEconomyRegionalEvidenceReceiptPayload,
|
|
8737
9084
|
canonicalEconomyRegionalEvidenceReceiptSigningPayload,
|
|
9085
|
+
canonicalOperatorAdjustmentDecisionPayload,
|
|
9086
|
+
canonicalOperatorAdjustmentExecutionPayload,
|
|
9087
|
+
canonicalOperatorAdjustmentPreviewPayload,
|
|
9088
|
+
canonicalOperatorAdjustmentProposalPayload,
|
|
8738
9089
|
canonicalPersonalWalletInitializationCommandPayload,
|
|
8739
9090
|
canonicalPersonalWalletInitializationOutboxPayload,
|
|
8740
9091
|
canonicalTransactionPayload,
|