@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.js
CHANGED
|
@@ -4319,6 +4319,341 @@ function assertDistinctAdjustmentApproval(request) {
|
|
|
4319
4319
|
}
|
|
4320
4320
|
}
|
|
4321
4321
|
|
|
4322
|
+
// src/operator-adjustments.ts
|
|
4323
|
+
var PREVIEW_KEYS = /* @__PURE__ */ new Set([
|
|
4324
|
+
"schemaVersion",
|
|
4325
|
+
"previewId",
|
|
4326
|
+
"adjustmentId",
|
|
4327
|
+
"operation",
|
|
4328
|
+
"targetAccountId",
|
|
4329
|
+
"targetComponent",
|
|
4330
|
+
"targetWalletId",
|
|
4331
|
+
"targetLedgerAccountId",
|
|
4332
|
+
"offsetLedgerAccountId",
|
|
4333
|
+
"sourceLotId",
|
|
4334
|
+
"amount",
|
|
4335
|
+
"reasonCode",
|
|
4336
|
+
"ticketReferenceHash",
|
|
4337
|
+
"transferPolicy",
|
|
4338
|
+
"refundPolicy",
|
|
4339
|
+
"originalSourceLotId",
|
|
4340
|
+
"originalTransactionId",
|
|
4341
|
+
"preparedAt",
|
|
4342
|
+
"expiresAt"
|
|
4343
|
+
]);
|
|
4344
|
+
var DECISION_KEYS = /* @__PURE__ */ new Set([
|
|
4345
|
+
"schemaVersion",
|
|
4346
|
+
"decisionId",
|
|
4347
|
+
"adjustmentId",
|
|
4348
|
+
"proposalId",
|
|
4349
|
+
"proposalHash",
|
|
4350
|
+
"previewHash",
|
|
4351
|
+
"decision",
|
|
4352
|
+
"proposedByAccountId",
|
|
4353
|
+
"decidedByAccountId",
|
|
4354
|
+
"proposedAt",
|
|
4355
|
+
"decidedAt"
|
|
4356
|
+
]);
|
|
4357
|
+
var PROPOSAL_KEYS = /* @__PURE__ */ new Set([
|
|
4358
|
+
"schemaVersion",
|
|
4359
|
+
"proposalId",
|
|
4360
|
+
"adjustmentId",
|
|
4361
|
+
"previewHash",
|
|
4362
|
+
"status",
|
|
4363
|
+
"proposedByAccountId",
|
|
4364
|
+
"proposedAt",
|
|
4365
|
+
"expiresAt"
|
|
4366
|
+
]);
|
|
4367
|
+
var EXECUTION_KEYS = /* @__PURE__ */ new Set([
|
|
4368
|
+
"schemaVersion",
|
|
4369
|
+
"executionId",
|
|
4370
|
+
"adjustmentId",
|
|
4371
|
+
"previewHash",
|
|
4372
|
+
"proposalHash",
|
|
4373
|
+
"decisionHash",
|
|
4374
|
+
"sourceLotId",
|
|
4375
|
+
"transactionId",
|
|
4376
|
+
"resultReceiptId",
|
|
4377
|
+
"executedAt"
|
|
4378
|
+
]);
|
|
4379
|
+
var OPERATIONS = /* @__PURE__ */ new Set([
|
|
4380
|
+
"credit",
|
|
4381
|
+
"reverse-credit"
|
|
4382
|
+
]);
|
|
4383
|
+
var TARGET_COMPONENTS = /* @__PURE__ */ new Set([
|
|
4384
|
+
"personal",
|
|
4385
|
+
"household-treasury"
|
|
4386
|
+
]);
|
|
4387
|
+
var TRANSFER_POLICIES = /* @__PURE__ */ new Set([
|
|
4388
|
+
"household-allocatable",
|
|
4389
|
+
"same-user-only",
|
|
4390
|
+
"non-transferable"
|
|
4391
|
+
]);
|
|
4392
|
+
var DECISIONS = /* @__PURE__ */ new Set([
|
|
4393
|
+
"approve",
|
|
4394
|
+
"reject"
|
|
4395
|
+
]);
|
|
4396
|
+
function assertExactKeys3(value, allowed, label) {
|
|
4397
|
+
economyAssert(
|
|
4398
|
+
value !== null && typeof value === "object" && !Array.isArray(value),
|
|
4399
|
+
"INVALID_CONTRACT",
|
|
4400
|
+
`${label} must be an object`
|
|
4401
|
+
);
|
|
4402
|
+
economyAssert(
|
|
4403
|
+
Object.keys(value).every((key) => allowed.has(key)),
|
|
4404
|
+
"INVALID_CONTRACT",
|
|
4405
|
+
`${label} contains an unsupported field`
|
|
4406
|
+
);
|
|
4407
|
+
}
|
|
4408
|
+
function assertCanonicalHash6(value, label) {
|
|
4409
|
+
economyAssert(
|
|
4410
|
+
/^sha256:[a-f0-9]{64}$/u.test(value),
|
|
4411
|
+
"INVALID_CONTRACT",
|
|
4412
|
+
`${label} must be a canonical SHA-256 reference`
|
|
4413
|
+
);
|
|
4414
|
+
}
|
|
4415
|
+
function assertReasonCode(reasonCode) {
|
|
4416
|
+
economyAssert(
|
|
4417
|
+
/^[A-Z][A-Z0-9_]{2,95}$/u.test(reasonCode),
|
|
4418
|
+
"INVALID_CONTRACT",
|
|
4419
|
+
"Adjustment reasonCode must be a bounded uppercase identifier"
|
|
4420
|
+
);
|
|
4421
|
+
}
|
|
4422
|
+
function assertOperatorAdjustmentPreview(preview) {
|
|
4423
|
+
assertExactKeys3(preview, PREVIEW_KEYS, "Operator adjustment preview");
|
|
4424
|
+
economyAssert(
|
|
4425
|
+
preview.schemaVersion === ECONOMY_CONTRACT_VERSION && OPERATIONS.has(preview.operation) && TARGET_COMPONENTS.has(preview.targetComponent) && TRANSFER_POLICIES.has(preview.transferPolicy) && preview.refundPolicy === "not-refundable",
|
|
4426
|
+
"INVALID_CONTRACT",
|
|
4427
|
+
"Unsupported operator adjustment preview"
|
|
4428
|
+
);
|
|
4429
|
+
assertEconomyIdentifier(preview.previewId, "previewId");
|
|
4430
|
+
assertEconomyIdentifier(preview.adjustmentId, "adjustmentId");
|
|
4431
|
+
assertEconomyIdentifier(preview.targetAccountId, "targetAccountId");
|
|
4432
|
+
assertEconomyIdentifier(preview.targetWalletId, "targetWalletId");
|
|
4433
|
+
assertEconomyIdentifier(
|
|
4434
|
+
preview.targetLedgerAccountId,
|
|
4435
|
+
"targetLedgerAccountId"
|
|
4436
|
+
);
|
|
4437
|
+
assertEconomyIdentifier(
|
|
4438
|
+
preview.offsetLedgerAccountId,
|
|
4439
|
+
"offsetLedgerAccountId"
|
|
4440
|
+
);
|
|
4441
|
+
assertEconomyIdentifier(preview.sourceLotId, "sourceLotId");
|
|
4442
|
+
economyAssert(
|
|
4443
|
+
parseTokenSubunits(preview.amount) > 0n,
|
|
4444
|
+
"INVALID_AMOUNT",
|
|
4445
|
+
"Operator adjustment amount must be positive"
|
|
4446
|
+
);
|
|
4447
|
+
assertReasonCode(preview.reasonCode);
|
|
4448
|
+
assertCanonicalHash6(preview.ticketReferenceHash, "ticketReferenceHash");
|
|
4449
|
+
const preparedAt = parseIsoTimestamp(preview.preparedAt);
|
|
4450
|
+
const expiresAt = parseIsoTimestamp(preview.expiresAt);
|
|
4451
|
+
economyAssert(
|
|
4452
|
+
expiresAt > preparedAt,
|
|
4453
|
+
"INVALID_TIME_WINDOW",
|
|
4454
|
+
"Operator adjustment preview must expire after preparation"
|
|
4455
|
+
);
|
|
4456
|
+
if (preview.operation === "credit") {
|
|
4457
|
+
economyAssert(
|
|
4458
|
+
preview.originalSourceLotId === void 0 && preview.originalTransactionId === void 0,
|
|
4459
|
+
"INVALID_CONTRACT",
|
|
4460
|
+
"A credit preview cannot bind an original transaction"
|
|
4461
|
+
);
|
|
4462
|
+
return;
|
|
4463
|
+
}
|
|
4464
|
+
economyAssert(
|
|
4465
|
+
preview.originalSourceLotId !== void 0 && preview.originalTransactionId !== void 0,
|
|
4466
|
+
"INVALID_CONTRACT",
|
|
4467
|
+
"A reversal preview must bind the original lot and transaction"
|
|
4468
|
+
);
|
|
4469
|
+
assertEconomyIdentifier(preview.originalSourceLotId, "originalSourceLotId");
|
|
4470
|
+
assertEconomyIdentifier(
|
|
4471
|
+
preview.originalTransactionId,
|
|
4472
|
+
"originalTransactionId"
|
|
4473
|
+
);
|
|
4474
|
+
}
|
|
4475
|
+
function canonicalOperatorAdjustmentPreviewPayload(preview) {
|
|
4476
|
+
assertOperatorAdjustmentPreview(preview);
|
|
4477
|
+
return JSON.stringify({
|
|
4478
|
+
schemaVersion: preview.schemaVersion,
|
|
4479
|
+
previewId: preview.previewId,
|
|
4480
|
+
adjustmentId: preview.adjustmentId,
|
|
4481
|
+
operation: preview.operation,
|
|
4482
|
+
targetAccountId: preview.targetAccountId,
|
|
4483
|
+
targetComponent: preview.targetComponent,
|
|
4484
|
+
targetWalletId: preview.targetWalletId,
|
|
4485
|
+
targetLedgerAccountId: preview.targetLedgerAccountId,
|
|
4486
|
+
offsetLedgerAccountId: preview.offsetLedgerAccountId,
|
|
4487
|
+
sourceLotId: preview.sourceLotId,
|
|
4488
|
+
amount: preview.amount,
|
|
4489
|
+
reasonCode: preview.reasonCode,
|
|
4490
|
+
ticketReferenceHash: preview.ticketReferenceHash,
|
|
4491
|
+
transferPolicy: preview.transferPolicy,
|
|
4492
|
+
refundPolicy: preview.refundPolicy,
|
|
4493
|
+
...preview.originalSourceLotId === void 0 ? {} : { originalSourceLotId: preview.originalSourceLotId },
|
|
4494
|
+
...preview.originalTransactionId === void 0 ? {} : { originalTransactionId: preview.originalTransactionId },
|
|
4495
|
+
preparedAt: preview.preparedAt,
|
|
4496
|
+
expiresAt: preview.expiresAt
|
|
4497
|
+
});
|
|
4498
|
+
}
|
|
4499
|
+
function assertOperatorAdjustmentProposal(proposal, preview, expectedPreviewHash) {
|
|
4500
|
+
assertOperatorAdjustmentPreview(preview);
|
|
4501
|
+
assertCanonicalHash6(expectedPreviewHash, "expectedPreviewHash");
|
|
4502
|
+
assertExactKeys3(proposal, PROPOSAL_KEYS, "Operator adjustment proposal");
|
|
4503
|
+
economyAssert(
|
|
4504
|
+
proposal.schemaVersion === ECONOMY_CONTRACT_VERSION && proposal.status === "pending-approval",
|
|
4505
|
+
"INVALID_CONTRACT",
|
|
4506
|
+
"Unsupported operator adjustment proposal"
|
|
4507
|
+
);
|
|
4508
|
+
assertEconomyIdentifier(proposal.proposalId, "proposalId");
|
|
4509
|
+
assertEconomyIdentifier(proposal.adjustmentId, "adjustmentId");
|
|
4510
|
+
assertCanonicalHash6(proposal.previewHash, "previewHash");
|
|
4511
|
+
assertEconomyIdentifier(
|
|
4512
|
+
proposal.proposedByAccountId,
|
|
4513
|
+
"proposedByAccountId"
|
|
4514
|
+
);
|
|
4515
|
+
economyAssert(
|
|
4516
|
+
proposal.adjustmentId === preview.adjustmentId && proposal.previewHash === expectedPreviewHash,
|
|
4517
|
+
"ADJUSTMENT_PREVIEW_MISMATCH",
|
|
4518
|
+
"Operator adjustment proposal does not match its preview"
|
|
4519
|
+
);
|
|
4520
|
+
const proposedAt = parseIsoTimestamp(proposal.proposedAt);
|
|
4521
|
+
const expiresAt = parseIsoTimestamp(proposal.expiresAt);
|
|
4522
|
+
economyAssert(
|
|
4523
|
+
proposedAt >= parseIsoTimestamp(preview.preparedAt) && expiresAt === parseIsoTimestamp(preview.expiresAt) && expiresAt > proposedAt,
|
|
4524
|
+
"INVALID_TIME_WINDOW",
|
|
4525
|
+
"Operator adjustment proposal times are inconsistent"
|
|
4526
|
+
);
|
|
4527
|
+
}
|
|
4528
|
+
function canonicalOperatorAdjustmentProposalPayload(proposal) {
|
|
4529
|
+
assertExactKeys3(proposal, PROPOSAL_KEYS, "Operator adjustment proposal");
|
|
4530
|
+
return JSON.stringify({
|
|
4531
|
+
schemaVersion: proposal.schemaVersion,
|
|
4532
|
+
proposalId: proposal.proposalId,
|
|
4533
|
+
adjustmentId: proposal.adjustmentId,
|
|
4534
|
+
previewHash: proposal.previewHash,
|
|
4535
|
+
status: proposal.status,
|
|
4536
|
+
proposedByAccountId: proposal.proposedByAccountId,
|
|
4537
|
+
proposedAt: proposal.proposedAt,
|
|
4538
|
+
expiresAt: proposal.expiresAt
|
|
4539
|
+
});
|
|
4540
|
+
}
|
|
4541
|
+
function assertOperatorAdjustmentDecision(decision, proposal, preview, expectedPreviewHash, expectedProposalHash) {
|
|
4542
|
+
assertOperatorAdjustmentProposal(proposal, preview, expectedPreviewHash);
|
|
4543
|
+
assertCanonicalHash6(expectedProposalHash, "expectedProposalHash");
|
|
4544
|
+
assertExactKeys3(decision, DECISION_KEYS, "Operator adjustment decision");
|
|
4545
|
+
economyAssert(
|
|
4546
|
+
decision.schemaVersion === ECONOMY_CONTRACT_VERSION && DECISIONS.has(decision.decision),
|
|
4547
|
+
"INVALID_CONTRACT",
|
|
4548
|
+
"Unsupported operator adjustment decision"
|
|
4549
|
+
);
|
|
4550
|
+
assertEconomyIdentifier(decision.decisionId, "decisionId");
|
|
4551
|
+
assertEconomyIdentifier(decision.adjustmentId, "adjustmentId");
|
|
4552
|
+
assertEconomyIdentifier(decision.proposalId, "proposalId");
|
|
4553
|
+
assertCanonicalHash6(decision.proposalHash, "proposalHash");
|
|
4554
|
+
assertCanonicalHash6(decision.previewHash, "previewHash");
|
|
4555
|
+
assertEconomyIdentifier(
|
|
4556
|
+
decision.proposedByAccountId,
|
|
4557
|
+
"proposedByAccountId"
|
|
4558
|
+
);
|
|
4559
|
+
assertEconomyIdentifier(
|
|
4560
|
+
decision.decidedByAccountId,
|
|
4561
|
+
"decidedByAccountId"
|
|
4562
|
+
);
|
|
4563
|
+
economyAssert(
|
|
4564
|
+
decision.proposedByAccountId !== decision.decidedByAccountId,
|
|
4565
|
+
"ADJUSTMENT_SELF_APPROVAL",
|
|
4566
|
+
"Operator adjustment approval requires a distinct operator"
|
|
4567
|
+
);
|
|
4568
|
+
economyAssert(
|
|
4569
|
+
decision.adjustmentId === preview.adjustmentId && decision.proposalId === proposal.proposalId && decision.proposalHash === expectedProposalHash && decision.previewHash === expectedPreviewHash,
|
|
4570
|
+
"ADJUSTMENT_PREVIEW_MISMATCH",
|
|
4571
|
+
"Operator adjustment decision does not match its preview"
|
|
4572
|
+
);
|
|
4573
|
+
const proposedAt = parseIsoTimestamp(decision.proposedAt);
|
|
4574
|
+
const decidedAt = parseIsoTimestamp(decision.decidedAt);
|
|
4575
|
+
economyAssert(
|
|
4576
|
+
decision.proposedByAccountId === proposal.proposedByAccountId && proposedAt === parseIsoTimestamp(proposal.proposedAt) && decidedAt >= proposedAt,
|
|
4577
|
+
"INVALID_TIME_WINDOW",
|
|
4578
|
+
"Operator adjustment decision times are inconsistent"
|
|
4579
|
+
);
|
|
4580
|
+
economyAssert(
|
|
4581
|
+
decidedAt <= parseIsoTimestamp(preview.expiresAt),
|
|
4582
|
+
"ADJUSTMENT_EXPIRED",
|
|
4583
|
+
"Operator adjustment preview has expired"
|
|
4584
|
+
);
|
|
4585
|
+
}
|
|
4586
|
+
function canonicalOperatorAdjustmentDecisionPayload(decision) {
|
|
4587
|
+
assertExactKeys3(decision, DECISION_KEYS, "Operator adjustment decision");
|
|
4588
|
+
return JSON.stringify({
|
|
4589
|
+
schemaVersion: decision.schemaVersion,
|
|
4590
|
+
decisionId: decision.decisionId,
|
|
4591
|
+
adjustmentId: decision.adjustmentId,
|
|
4592
|
+
proposalId: decision.proposalId,
|
|
4593
|
+
proposalHash: decision.proposalHash,
|
|
4594
|
+
previewHash: decision.previewHash,
|
|
4595
|
+
decision: decision.decision,
|
|
4596
|
+
proposedByAccountId: decision.proposedByAccountId,
|
|
4597
|
+
decidedByAccountId: decision.decidedByAccountId,
|
|
4598
|
+
proposedAt: decision.proposedAt,
|
|
4599
|
+
decidedAt: decision.decidedAt
|
|
4600
|
+
});
|
|
4601
|
+
}
|
|
4602
|
+
function assertOperatorAdjustmentExecution(execution, preview, proposal, decision, expectedPreviewHash, expectedProposalHash, expectedDecisionHash) {
|
|
4603
|
+
assertOperatorAdjustmentDecision(
|
|
4604
|
+
decision,
|
|
4605
|
+
proposal,
|
|
4606
|
+
preview,
|
|
4607
|
+
expectedPreviewHash,
|
|
4608
|
+
expectedProposalHash
|
|
4609
|
+
);
|
|
4610
|
+
assertCanonicalHash6(expectedDecisionHash, "expectedDecisionHash");
|
|
4611
|
+
assertExactKeys3(execution, EXECUTION_KEYS, "Operator adjustment execution");
|
|
4612
|
+
economyAssert(
|
|
4613
|
+
execution.schemaVersion === ECONOMY_CONTRACT_VERSION,
|
|
4614
|
+
"INVALID_CONTRACT",
|
|
4615
|
+
"Unsupported operator adjustment execution"
|
|
4616
|
+
);
|
|
4617
|
+
assertEconomyIdentifier(execution.executionId, "executionId");
|
|
4618
|
+
assertEconomyIdentifier(execution.adjustmentId, "adjustmentId");
|
|
4619
|
+
assertCanonicalHash6(execution.previewHash, "previewHash");
|
|
4620
|
+
assertCanonicalHash6(execution.proposalHash, "proposalHash");
|
|
4621
|
+
assertCanonicalHash6(execution.decisionHash, "decisionHash");
|
|
4622
|
+
assertEconomyIdentifier(execution.sourceLotId, "sourceLotId");
|
|
4623
|
+
assertEconomyIdentifier(execution.transactionId, "transactionId");
|
|
4624
|
+
assertEconomyIdentifier(execution.resultReceiptId, "resultReceiptId");
|
|
4625
|
+
economyAssert(
|
|
4626
|
+
decision.decision === "approve",
|
|
4627
|
+
"ADJUSTMENT_NOT_APPROVED",
|
|
4628
|
+
"Only an approved adjustment may execute"
|
|
4629
|
+
);
|
|
4630
|
+
economyAssert(
|
|
4631
|
+
execution.adjustmentId === preview.adjustmentId && execution.previewHash === expectedPreviewHash && execution.proposalHash === expectedProposalHash && execution.decisionHash === expectedDecisionHash && execution.sourceLotId === preview.sourceLotId,
|
|
4632
|
+
"ADJUSTMENT_PREVIEW_MISMATCH",
|
|
4633
|
+
"Operator adjustment execution does not match its approval plan"
|
|
4634
|
+
);
|
|
4635
|
+
economyAssert(
|
|
4636
|
+
parseIsoTimestamp(execution.executedAt) >= parseIsoTimestamp(decision.decidedAt),
|
|
4637
|
+
"INVALID_TIME_WINDOW",
|
|
4638
|
+
"Operator adjustment execution predates its decision"
|
|
4639
|
+
);
|
|
4640
|
+
}
|
|
4641
|
+
function canonicalOperatorAdjustmentExecutionPayload(execution) {
|
|
4642
|
+
assertExactKeys3(execution, EXECUTION_KEYS, "Operator adjustment execution");
|
|
4643
|
+
return JSON.stringify({
|
|
4644
|
+
schemaVersion: execution.schemaVersion,
|
|
4645
|
+
executionId: execution.executionId,
|
|
4646
|
+
adjustmentId: execution.adjustmentId,
|
|
4647
|
+
previewHash: execution.previewHash,
|
|
4648
|
+
proposalHash: execution.proposalHash,
|
|
4649
|
+
decisionHash: execution.decisionHash,
|
|
4650
|
+
sourceLotId: execution.sourceLotId,
|
|
4651
|
+
transactionId: execution.transactionId,
|
|
4652
|
+
resultReceiptId: execution.resultReceiptId,
|
|
4653
|
+
executedAt: execution.executedAt
|
|
4654
|
+
});
|
|
4655
|
+
}
|
|
4656
|
+
|
|
4322
4657
|
// src/paid-lots.ts
|
|
4323
4658
|
var ZERO_ARITHMETIC = Object.freeze({
|
|
4324
4659
|
retainedDelta: serializeTokenSubunits(0n),
|
|
@@ -6859,7 +7194,7 @@ var PORTABLE_KEYS = /* @__PURE__ */ new Set([
|
|
|
6859
7194
|
"signature",
|
|
6860
7195
|
...PORTABLE_BODY_KEYS
|
|
6861
7196
|
]);
|
|
6862
|
-
function
|
|
7197
|
+
function assertExactKeys4(value, allowedKeys, label) {
|
|
6863
7198
|
economyAssert(
|
|
6864
7199
|
value !== null && typeof value === "object" && !Array.isArray(value),
|
|
6865
7200
|
"INVALID_CONTRACT",
|
|
@@ -6871,7 +7206,7 @@ function assertExactKeys3(value, allowedKeys, label) {
|
|
|
6871
7206
|
`${label} contains an unsupported field`
|
|
6872
7207
|
);
|
|
6873
7208
|
}
|
|
6874
|
-
function
|
|
7209
|
+
function assertCanonicalHash7(value, label) {
|
|
6875
7210
|
economyAssert(
|
|
6876
7211
|
typeof value === "string" && CANONICAL_HASH.test(value),
|
|
6877
7212
|
"INVALID_CONTRACT",
|
|
@@ -6880,7 +7215,7 @@ function assertCanonicalHash6(value, label) {
|
|
|
6880
7215
|
}
|
|
6881
7216
|
function canonicalHash(payload, hashCanonicalPayload2, label) {
|
|
6882
7217
|
const value = hashCanonicalPayload2(payload);
|
|
6883
|
-
|
|
7218
|
+
assertCanonicalHash7(value, label);
|
|
6884
7219
|
return value;
|
|
6885
7220
|
}
|
|
6886
7221
|
function assertUnsignedInteger(value, label) {
|
|
@@ -6948,7 +7283,7 @@ function canonicalSignatureMetadata(signature) {
|
|
|
6948
7283
|
};
|
|
6949
7284
|
}
|
|
6950
7285
|
function assertEconomySealedRecoveryPayload(payload) {
|
|
6951
|
-
|
|
7286
|
+
assertExactKeys4(
|
|
6952
7287
|
payload,
|
|
6953
7288
|
/* @__PURE__ */ new Set([
|
|
6954
7289
|
"schemaVersion",
|
|
@@ -6978,17 +7313,17 @@ function assertEconomySealedRecoveryPayload(payload) {
|
|
|
6978
7313
|
22,
|
|
6979
7314
|
22
|
|
6980
7315
|
);
|
|
6981
|
-
|
|
7316
|
+
assertCanonicalHash7(
|
|
6982
7317
|
payload.plaintextContentHash,
|
|
6983
7318
|
"Recovery plaintext-content hash"
|
|
6984
7319
|
);
|
|
6985
|
-
|
|
7320
|
+
assertCanonicalHash7(
|
|
6986
7321
|
payload.encryptionContextHash,
|
|
6987
7322
|
"Recovery encryption-context hash"
|
|
6988
7323
|
);
|
|
6989
7324
|
}
|
|
6990
7325
|
function assertAcceptanceBody(body) {
|
|
6991
|
-
|
|
7326
|
+
assertExactKeys4(
|
|
6992
7327
|
body,
|
|
6993
7328
|
"acceptanceEnvelopeId" in body ? ACCEPTANCE_KEYS : ACCEPTANCE_BODY_KEYS,
|
|
6994
7329
|
"Recovery acceptance body"
|
|
@@ -7007,9 +7342,9 @@ function assertAcceptanceBody(body) {
|
|
|
7007
7342
|
body.idempotencyFingerprint,
|
|
7008
7343
|
"economy.idempotency-key.v1"
|
|
7009
7344
|
);
|
|
7010
|
-
|
|
7345
|
+
assertCanonicalHash7(body.commandEnvelopeHash, "Command-envelope hash");
|
|
7011
7346
|
assertEconomyIdentifier(body.acceptedReceiptId, "acceptedReceiptId");
|
|
7012
|
-
|
|
7347
|
+
assertCanonicalHash7(body.acceptedReceiptHash, "Accepted-receipt hash");
|
|
7013
7348
|
assertEconomySealedRecoveryPayload(body.sealedPayload);
|
|
7014
7349
|
const preparedAt = parseIsoTimestamp(body.preparedAt);
|
|
7015
7350
|
const acceptedAt = parseIsoTimestamp(body.acceptedAt);
|
|
@@ -7057,7 +7392,7 @@ function createEconomyRecoveryAcceptanceEnvelope(body, hashCanonicalPayload2) {
|
|
|
7057
7392
|
};
|
|
7058
7393
|
}
|
|
7059
7394
|
function assertEconomyRecoveryAcceptanceEnvelope(envelope, hashCanonicalPayload2) {
|
|
7060
|
-
|
|
7395
|
+
assertExactKeys4(envelope, ACCEPTANCE_KEYS, "Recovery acceptance envelope");
|
|
7061
7396
|
assertAcceptanceBody(envelope);
|
|
7062
7397
|
assertEconomyIdentifier(
|
|
7063
7398
|
envelope.acceptanceEnvelopeId,
|
|
@@ -7098,7 +7433,7 @@ function canonicalEconomyRecoveryAcceptanceEnvelopePayload(envelope, hashCanonic
|
|
|
7098
7433
|
});
|
|
7099
7434
|
}
|
|
7100
7435
|
function assertCommittedResultBody(body) {
|
|
7101
|
-
|
|
7436
|
+
assertExactKeys4(
|
|
7102
7437
|
body,
|
|
7103
7438
|
"committedResultId" in body ? COMMITTED_RESULT_KEYS : COMMITTED_RESULT_BODY_KEYS,
|
|
7104
7439
|
"Recovery committed-result body"
|
|
@@ -7126,7 +7461,7 @@ function assertCommittedResultBody(body) {
|
|
|
7126
7461
|
[body.authorityCommitHash, "Authority-commit hash"],
|
|
7127
7462
|
[body.authorityHeadHashAfter, "Authority-head hash"]
|
|
7128
7463
|
]) {
|
|
7129
|
-
|
|
7464
|
+
assertCanonicalHash7(value, label);
|
|
7130
7465
|
}
|
|
7131
7466
|
economyAssert(
|
|
7132
7467
|
RESULT_OUTCOMES.has(body.outcome),
|
|
@@ -7149,7 +7484,7 @@ function assertCommittedResultBody(body) {
|
|
|
7149
7484
|
assertEconomyIdentifier(body.transactionId, "transactionId");
|
|
7150
7485
|
}
|
|
7151
7486
|
if (body.transactionCanonicalHash !== void 0) {
|
|
7152
|
-
|
|
7487
|
+
assertCanonicalHash7(
|
|
7153
7488
|
body.transactionCanonicalHash,
|
|
7154
7489
|
"Transaction canonical hash"
|
|
7155
7490
|
);
|
|
@@ -7192,7 +7527,7 @@ function createEconomyRecoveryCommittedResult(body, hashCanonicalPayload2) {
|
|
|
7192
7527
|
};
|
|
7193
7528
|
}
|
|
7194
7529
|
function assertEconomyRecoveryCommittedResult(result, hashCanonicalPayload2) {
|
|
7195
|
-
|
|
7530
|
+
assertExactKeys4(
|
|
7196
7531
|
result,
|
|
7197
7532
|
COMMITTED_RESULT_KEYS,
|
|
7198
7533
|
"Recovery committed result"
|
|
@@ -7251,7 +7586,7 @@ function assertEconomyRecoveryResultLink(acceptance, result, hashCanonicalPayloa
|
|
|
7251
7586
|
);
|
|
7252
7587
|
}
|
|
7253
7588
|
function assertEconomyEvidenceSignatureMetadata(signature) {
|
|
7254
|
-
|
|
7589
|
+
assertExactKeys4(
|
|
7255
7590
|
signature,
|
|
7256
7591
|
/* @__PURE__ */ new Set([
|
|
7257
7592
|
"schemaVersion",
|
|
@@ -7271,7 +7606,7 @@ function assertEconomyEvidenceSignatureMetadata(signature) {
|
|
|
7271
7606
|
parseIsoTimestamp(signature.signedAt);
|
|
7272
7607
|
}
|
|
7273
7608
|
function assertEconomyEvidenceSignature(signature) {
|
|
7274
|
-
|
|
7609
|
+
assertExactKeys4(
|
|
7275
7610
|
signature,
|
|
7276
7611
|
/* @__PURE__ */ new Set([
|
|
7277
7612
|
"schemaVersion",
|
|
@@ -7293,7 +7628,7 @@ function assertEconomyEvidenceSignature(signature) {
|
|
|
7293
7628
|
assertBase64url(signature.value, "Evidence signature value", 32, 2048);
|
|
7294
7629
|
}
|
|
7295
7630
|
function assertRegionalEvidenceBody(body) {
|
|
7296
|
-
|
|
7631
|
+
assertExactKeys4(
|
|
7297
7632
|
body,
|
|
7298
7633
|
"evidenceReceiptId" in body ? REGIONAL_KEYS : REGIONAL_BODY_KEYS,
|
|
7299
7634
|
"Regional evidence-receipt body"
|
|
@@ -7325,7 +7660,7 @@ function assertRegionalEvidenceBody(body) {
|
|
|
7325
7660
|
"INVALID_CONTRACT",
|
|
7326
7661
|
"Unsupported recovery record kind"
|
|
7327
7662
|
);
|
|
7328
|
-
|
|
7663
|
+
assertCanonicalHash7(
|
|
7329
7664
|
body.recoveryRecordContentHash,
|
|
7330
7665
|
"Recovery-record content hash"
|
|
7331
7666
|
);
|
|
@@ -7341,7 +7676,7 @@ function assertRegionalEvidenceBody(body) {
|
|
|
7341
7676
|
"INVALID_CONTRACT",
|
|
7342
7677
|
"Non-genesis regional evidence receipt requires a previous hash"
|
|
7343
7678
|
);
|
|
7344
|
-
|
|
7679
|
+
assertCanonicalHash7(
|
|
7345
7680
|
body.previousReceiptHash,
|
|
7346
7681
|
"Previous evidence-receipt hash"
|
|
7347
7682
|
);
|
|
@@ -7385,7 +7720,7 @@ function createEconomyRegionalEvidenceReceipt(body, signature, hashCanonicalPayl
|
|
|
7385
7720
|
};
|
|
7386
7721
|
}
|
|
7387
7722
|
function assertEconomyRegionalEvidenceReceipt(receipt, hashCanonicalPayload2) {
|
|
7388
|
-
|
|
7723
|
+
assertExactKeys4(receipt, REGIONAL_KEYS, "Regional evidence receipt");
|
|
7389
7724
|
assertRegionalEvidenceBody(receipt);
|
|
7390
7725
|
assertEconomyIdentifier(receipt.evidenceReceiptId, "evidenceReceiptId");
|
|
7391
7726
|
assertEconomyEvidenceSignature(receipt.signature);
|
|
@@ -7516,7 +7851,7 @@ function assertEconomyRegionalEvidenceChain(receipts, expectedPreviousReceiptHas
|
|
|
7516
7851
|
"INVALID_CONTRACT",
|
|
7517
7852
|
"Partial evidence chain requires its trusted preceding hash"
|
|
7518
7853
|
);
|
|
7519
|
-
|
|
7854
|
+
assertCanonicalHash7(
|
|
7520
7855
|
expectedPreviousReceiptHash,
|
|
7521
7856
|
"Expected preceding evidence-receipt hash"
|
|
7522
7857
|
);
|
|
@@ -7587,7 +7922,7 @@ function assertEconomyRegionalEvidenceEquality(receipts, expectedRegions, hashCa
|
|
|
7587
7922
|
);
|
|
7588
7923
|
}
|
|
7589
7924
|
function assertEconomyMerkleInclusionProof(proof) {
|
|
7590
|
-
|
|
7925
|
+
assertExactKeys4(
|
|
7591
7926
|
proof,
|
|
7592
7927
|
/* @__PURE__ */ new Set([
|
|
7593
7928
|
"schemaVersion",
|
|
@@ -7608,8 +7943,8 @@ function assertEconomyMerkleInclusionProof(proof) {
|
|
|
7608
7943
|
"Unsupported Merkle inclusion proof"
|
|
7609
7944
|
);
|
|
7610
7945
|
assertEconomyIdentifier(proof.anchorId, "anchorId");
|
|
7611
|
-
|
|
7612
|
-
|
|
7946
|
+
assertCanonicalHash7(proof.anchorManifestHash, "Anchor-manifest hash");
|
|
7947
|
+
assertCanonicalHash7(proof.leafHash, "Merkle leaf hash");
|
|
7613
7948
|
assertUnsignedInteger(proof.leafIndex, "Merkle leaf index");
|
|
7614
7949
|
assertUnsignedInteger(proof.leafCount, "Merkle leaf count");
|
|
7615
7950
|
economyAssert(
|
|
@@ -7618,7 +7953,7 @@ function assertEconomyMerkleInclusionProof(proof) {
|
|
|
7618
7953
|
"Merkle leaf position is outside its bounded tree"
|
|
7619
7954
|
);
|
|
7620
7955
|
for (const step of proof.siblings) {
|
|
7621
|
-
|
|
7956
|
+
assertExactKeys4(
|
|
7622
7957
|
step,
|
|
7623
7958
|
/* @__PURE__ */ new Set(["schemaVersion", "side", "hash"]),
|
|
7624
7959
|
"Merkle proof step"
|
|
@@ -7628,7 +7963,7 @@ function assertEconomyMerkleInclusionProof(proof) {
|
|
|
7628
7963
|
"INVALID_CONTRACT",
|
|
7629
7964
|
"Unsupported Merkle proof step"
|
|
7630
7965
|
);
|
|
7631
|
-
|
|
7966
|
+
assertCanonicalHash7(step.hash, "Merkle sibling hash");
|
|
7632
7967
|
}
|
|
7633
7968
|
}
|
|
7634
7969
|
function canonicalMerkleProof(proof) {
|
|
@@ -7707,7 +8042,7 @@ function assertEconomyMerkleInclusion(proof, anchor, hashCanonicalPayload2) {
|
|
|
7707
8042
|
);
|
|
7708
8043
|
}
|
|
7709
8044
|
function assertPortableEvidenceReference(reference) {
|
|
7710
|
-
|
|
8045
|
+
assertExactKeys4(
|
|
7711
8046
|
reference,
|
|
7712
8047
|
/* @__PURE__ */ new Set([
|
|
7713
8048
|
"schemaVersion",
|
|
@@ -7727,7 +8062,7 @@ function assertPortableEvidenceReference(reference) {
|
|
|
7727
8062
|
reference.evidenceReceiptId,
|
|
7728
8063
|
"evidenceReceiptId"
|
|
7729
8064
|
);
|
|
7730
|
-
|
|
8065
|
+
assertCanonicalHash7(
|
|
7731
8066
|
reference.evidenceReceiptHash,
|
|
7732
8067
|
"Evidence-receipt hash"
|
|
7733
8068
|
);
|
|
@@ -7744,7 +8079,7 @@ function canonicalPortableEvidenceReference(reference) {
|
|
|
7744
8079
|
};
|
|
7745
8080
|
}
|
|
7746
8081
|
function assertPortableBody(body) {
|
|
7747
|
-
|
|
8082
|
+
assertExactKeys4(
|
|
7748
8083
|
body,
|
|
7749
8084
|
"portableReceiptId" in body ? PORTABLE_KEYS : PORTABLE_BODY_KEYS,
|
|
7750
8085
|
"Portable customer-receipt body"
|
|
@@ -7783,7 +8118,7 @@ function assertPortableBody(body) {
|
|
|
7783
8118
|
[body.committedResultContentHash, "Committed-result content hash"],
|
|
7784
8119
|
[body.authorityCommitHash, "Authority-commit hash"]
|
|
7785
8120
|
]) {
|
|
7786
|
-
|
|
8121
|
+
assertCanonicalHash7(value, label);
|
|
7787
8122
|
}
|
|
7788
8123
|
assertUnsignedInteger(body.authoritySequence, "Authority sequence");
|
|
7789
8124
|
economyAssert(
|
|
@@ -7868,7 +8203,7 @@ function createEconomyPortableCustomerReceipt(body, signature, hashCanonicalPayl
|
|
|
7868
8203
|
};
|
|
7869
8204
|
}
|
|
7870
8205
|
function assertEconomyPortableCustomerReceipt(receipt, hashCanonicalPayload2) {
|
|
7871
|
-
|
|
8206
|
+
assertExactKeys4(receipt, PORTABLE_KEYS, "Portable customer receipt");
|
|
7872
8207
|
assertPortableBody(receipt);
|
|
7873
8208
|
assertEconomyIdentifier(receipt.portableReceiptId, "portableReceiptId");
|
|
7874
8209
|
assertEconomyEvidenceSignature(receipt.signature);
|
|
@@ -8168,7 +8503,7 @@ var DOCUMENT_ID_KEYS = /* @__PURE__ */ new Set([
|
|
|
8168
8503
|
"lifetimeProjectionId",
|
|
8169
8504
|
"outboxEventId"
|
|
8170
8505
|
]);
|
|
8171
|
-
function
|
|
8506
|
+
function assertExactKeys5(value, allowed, label) {
|
|
8172
8507
|
economyAssert(
|
|
8173
8508
|
value !== null && typeof value === "object" && !Array.isArray(value),
|
|
8174
8509
|
"INVALID_CONTRACT",
|
|
@@ -8208,7 +8543,7 @@ function createPersonalWalletInitializationDocumentIds(subjectAccountId, hash) {
|
|
|
8208
8543
|
};
|
|
8209
8544
|
}
|
|
8210
8545
|
function assertPersonalWalletInitializationCommand(command) {
|
|
8211
|
-
|
|
8546
|
+
assertExactKeys5(command, COMMAND_KEYS, "Wallet initialization command");
|
|
8212
8547
|
economyAssert(
|
|
8213
8548
|
command.schemaVersion === ECONOMY_CONTRACT_VERSION && command.commandType === "initialize-wallet" && command.walletKind === "personal",
|
|
8214
8549
|
"INVALID_CONTRACT",
|
|
@@ -8232,7 +8567,7 @@ function canonicalPersonalWalletInitializationCommandPayload(command) {
|
|
|
8232
8567
|
});
|
|
8233
8568
|
}
|
|
8234
8569
|
function assertPersonalWalletInitializationOutboxIntent(intent) {
|
|
8235
|
-
|
|
8570
|
+
assertExactKeys5(intent, OUTBOX_KEYS, "Wallet initialization outbox intent");
|
|
8236
8571
|
economyAssert(
|
|
8237
8572
|
intent.schemaVersion === ECONOMY_CONTRACT_VERSION && intent.eventType === "wallet.initialized.v1",
|
|
8238
8573
|
"INVALID_CONTRACT",
|
|
@@ -8332,8 +8667,8 @@ function createPersonalWalletInitializationState(input, hash) {
|
|
|
8332
8667
|
return state;
|
|
8333
8668
|
}
|
|
8334
8669
|
function assertPersonalWalletInitializationState(state) {
|
|
8335
|
-
|
|
8336
|
-
|
|
8670
|
+
assertExactKeys5(state, STATE_KEYS, "Wallet initialization state");
|
|
8671
|
+
assertExactKeys5(
|
|
8337
8672
|
state.documentIds,
|
|
8338
8673
|
DOCUMENT_ID_KEYS,
|
|
8339
8674
|
"Wallet initialization document IDs"
|
|
@@ -8444,6 +8779,10 @@ export {
|
|
|
8444
8779
|
assertModuleSpendQuote,
|
|
8445
8780
|
assertNonNegativeAccounts,
|
|
8446
8781
|
assertOpenPurchaseIntent,
|
|
8782
|
+
assertOperatorAdjustmentDecision,
|
|
8783
|
+
assertOperatorAdjustmentExecution,
|
|
8784
|
+
assertOperatorAdjustmentPreview,
|
|
8785
|
+
assertOperatorAdjustmentProposal,
|
|
8447
8786
|
assertPaidLotLifecycle,
|
|
8448
8787
|
assertPaidLotLifecycleEvent,
|
|
8449
8788
|
assertPaidLotPurchaseProvenance,
|
|
@@ -8507,6 +8846,10 @@ export {
|
|
|
8507
8846
|
canonicalEconomyRegionalEvidenceReceiptBodyPayload,
|
|
8508
8847
|
canonicalEconomyRegionalEvidenceReceiptPayload,
|
|
8509
8848
|
canonicalEconomyRegionalEvidenceReceiptSigningPayload,
|
|
8849
|
+
canonicalOperatorAdjustmentDecisionPayload,
|
|
8850
|
+
canonicalOperatorAdjustmentExecutionPayload,
|
|
8851
|
+
canonicalOperatorAdjustmentPreviewPayload,
|
|
8852
|
+
canonicalOperatorAdjustmentProposalPayload,
|
|
8510
8853
|
canonicalPersonalWalletInitializationCommandPayload,
|
|
8511
8854
|
canonicalPersonalWalletInitializationOutboxPayload,
|
|
8512
8855
|
canonicalTransactionPayload,
|