@plasius/economy 0.8.0 → 0.10.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 +26 -1
- package/dist/index.cjs +370 -30
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +97 -4
- package/dist/index.d.ts +97 -4
- package/dist/index.js +362 -30
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1895,7 +1895,8 @@ var COMMAND_TYPES = /* @__PURE__ */ new Set([
|
|
|
1895
1895
|
"chargeback",
|
|
1896
1896
|
"reverse",
|
|
1897
1897
|
"adjust",
|
|
1898
|
-
"initialize-wallet"
|
|
1898
|
+
"initialize-wallet",
|
|
1899
|
+
"initialize-admin-reporting"
|
|
1899
1900
|
]);
|
|
1900
1901
|
var COMMAND_SOURCES = /* @__PURE__ */ new Set([
|
|
1901
1902
|
"browser",
|
|
@@ -1930,6 +1931,7 @@ var PROVIDERS = /* @__PURE__ */ new Set([
|
|
|
1930
1931
|
]);
|
|
1931
1932
|
var FINGERPRINT_DOMAINS = /* @__PURE__ */ new Set([
|
|
1932
1933
|
"economy.idempotency-key.v1",
|
|
1934
|
+
"economy.google-reporting-key.v1",
|
|
1933
1935
|
"economy.provider-event-key.v1",
|
|
1934
1936
|
"economy.provider-object-key.v1",
|
|
1935
1937
|
"economy.provider-payload.v1",
|
|
@@ -1959,6 +1961,7 @@ var SOURCE_COMMAND_TYPES = {
|
|
|
1959
1961
|
system: /* @__PURE__ */ new Set([
|
|
1960
1962
|
"credit-event",
|
|
1961
1963
|
"credit-competition",
|
|
1964
|
+
"initialize-admin-reporting",
|
|
1962
1965
|
"hold",
|
|
1963
1966
|
"release-hold",
|
|
1964
1967
|
"reverse"
|
|
@@ -3439,6 +3442,7 @@ var ACTIVITY_SOURCES2 = /* @__PURE__ */ new Set([
|
|
|
3439
3442
|
"shopify",
|
|
3440
3443
|
"ayet",
|
|
3441
3444
|
"bitlabs",
|
|
3445
|
+
"google-ad-manager",
|
|
3442
3446
|
"subscription",
|
|
3443
3447
|
"event",
|
|
3444
3448
|
"competition",
|
|
@@ -4232,6 +4236,324 @@ function evaluateEarlyBackerBySettlementV2(payerAccountId, receivingHouseholdId,
|
|
|
4232
4236
|
};
|
|
4233
4237
|
}
|
|
4234
4238
|
|
|
4239
|
+
// src/google-rewarded-web.ts
|
|
4240
|
+
var GOOGLE_REWARDED_WEB_PROVIDER = "google-ad-manager";
|
|
4241
|
+
var GOOGLE_REWARDED_WEB_NOMINAL_MICROS_PER_TOKEN = 100000n;
|
|
4242
|
+
var GOOGLE_REWARDED_WEB_MINIMUM_NET_MICROS_PER_TOKEN = 125000n;
|
|
4243
|
+
var SIGNED_BIGINT_MAX = 2n ** 63n - 1n;
|
|
4244
|
+
var CANONICAL_UNSIGNED_INTEGER = /^(?:0|[1-9][0-9]*)$/u;
|
|
4245
|
+
var SHA256 = /^sha256:[a-f0-9]{64}$/u;
|
|
4246
|
+
function assertExactKeys4(value, allowed, label) {
|
|
4247
|
+
economyAssert(
|
|
4248
|
+
Object.keys(value).every((key) => allowed.has(key)) && [...allowed].every(
|
|
4249
|
+
(key) => key === "effectiveUntil" || Object.prototype.hasOwnProperty.call(value, key)
|
|
4250
|
+
),
|
|
4251
|
+
"INVALID_CONTRACT",
|
|
4252
|
+
`${label} contains missing or unsupported fields`
|
|
4253
|
+
);
|
|
4254
|
+
}
|
|
4255
|
+
function parseGbpMicros(value, label) {
|
|
4256
|
+
economyAssert(
|
|
4257
|
+
typeof value === "string" && CANONICAL_UNSIGNED_INTEGER.test(value),
|
|
4258
|
+
"INVALID_CONTRACT",
|
|
4259
|
+
`${label} must be canonical non-negative GBP micros`
|
|
4260
|
+
);
|
|
4261
|
+
const parsed = BigInt(value);
|
|
4262
|
+
economyAssert(
|
|
4263
|
+
parsed <= SIGNED_BIGINT_MAX,
|
|
4264
|
+
"AMOUNT_OUT_OF_RANGE",
|
|
4265
|
+
`${label} is outside the signed 64-bit range`
|
|
4266
|
+
);
|
|
4267
|
+
return parsed;
|
|
4268
|
+
}
|
|
4269
|
+
function assertRewardPayload(payload) {
|
|
4270
|
+
assertExactKeys4(payload, /* @__PURE__ */ new Set(["type", "amount"]), "Reward payload");
|
|
4271
|
+
economyAssert(
|
|
4272
|
+
payload.type === "plasius-token-progress" && payload.amount === 1,
|
|
4273
|
+
"INVALID_CONTRACT",
|
|
4274
|
+
"Reward payload must disclose exactly one Token of bundle progress"
|
|
4275
|
+
);
|
|
4276
|
+
}
|
|
4277
|
+
function assertBoundedCount(value, label) {
|
|
4278
|
+
economyAssert(
|
|
4279
|
+
Number.isSafeInteger(value) && value >= 0,
|
|
4280
|
+
"INVALID_CONTRACT",
|
|
4281
|
+
`${label} must be a non-negative safe integer`
|
|
4282
|
+
);
|
|
4283
|
+
}
|
|
4284
|
+
function createGoogleRewardedWebQuote(input) {
|
|
4285
|
+
const gross = parseGbpMicros(
|
|
4286
|
+
input.grossRevenueFloorMicros,
|
|
4287
|
+
"grossRevenueFloorMicros"
|
|
4288
|
+
);
|
|
4289
|
+
const providerFee = parseGbpMicros(
|
|
4290
|
+
input.providerFeeMicros,
|
|
4291
|
+
"providerFeeMicros"
|
|
4292
|
+
);
|
|
4293
|
+
const invalidTrafficHaircut = parseGbpMicros(
|
|
4294
|
+
input.invalidTrafficHaircutMicros,
|
|
4295
|
+
"invalidTrafficHaircutMicros"
|
|
4296
|
+
);
|
|
4297
|
+
const otherCost = parseGbpMicros(input.otherCostMicros, "otherCostMicros");
|
|
4298
|
+
const deductions = providerFee + invalidTrafficHaircut + otherCost;
|
|
4299
|
+
economyAssert(
|
|
4300
|
+
deductions <= gross,
|
|
4301
|
+
"INVALID_CONTRACT",
|
|
4302
|
+
"Rewarded-web costs cannot exceed the gross revenue floor"
|
|
4303
|
+
);
|
|
4304
|
+
const eligibleNet = gross - deductions;
|
|
4305
|
+
const retainedMargin = eligibleNet - GOOGLE_REWARDED_WEB_NOMINAL_MICROS_PER_TOKEN;
|
|
4306
|
+
const quote = {
|
|
4307
|
+
schemaVersion: ECONOMY_CONTRACT_VERSION,
|
|
4308
|
+
quoteVersion: input.quoteVersion,
|
|
4309
|
+
provider: GOOGLE_REWARDED_WEB_PROVIDER,
|
|
4310
|
+
currency: "GBP",
|
|
4311
|
+
bundleCompletions: input.bundleCompletions,
|
|
4312
|
+
rewardPayload: input.rewardPayload,
|
|
4313
|
+
grossRevenueFloorMicros: gross.toString(10),
|
|
4314
|
+
providerFeeMicros: providerFee.toString(10),
|
|
4315
|
+
invalidTrafficHaircutMicros: invalidTrafficHaircut.toString(10),
|
|
4316
|
+
otherCostMicros: otherCost.toString(10),
|
|
4317
|
+
eligibleNetRevenueMicros: eligibleNet.toString(10),
|
|
4318
|
+
tokenAmount: serializeTokenSubunits(TOKEN_SUBUNITS_PER_TOKEN),
|
|
4319
|
+
nominalLiabilityMicros: GOOGLE_REWARDED_WEB_NOMINAL_MICROS_PER_TOKEN.toString(10),
|
|
4320
|
+
retainedMarginMicros: retainedMargin.toString(10),
|
|
4321
|
+
effectiveFrom: input.effectiveFrom,
|
|
4322
|
+
...input.effectiveUntil === void 0 ? {} : { effectiveUntil: input.effectiveUntil }
|
|
4323
|
+
};
|
|
4324
|
+
assertGoogleRewardedWebQuote(quote);
|
|
4325
|
+
return Object.freeze(quote);
|
|
4326
|
+
}
|
|
4327
|
+
function assertGoogleRewardedWebQuote(quote) {
|
|
4328
|
+
assertExactKeys4(
|
|
4329
|
+
quote,
|
|
4330
|
+
/* @__PURE__ */ new Set([
|
|
4331
|
+
"schemaVersion",
|
|
4332
|
+
"quoteVersion",
|
|
4333
|
+
"provider",
|
|
4334
|
+
"currency",
|
|
4335
|
+
"bundleCompletions",
|
|
4336
|
+
"rewardPayload",
|
|
4337
|
+
"grossRevenueFloorMicros",
|
|
4338
|
+
"providerFeeMicros",
|
|
4339
|
+
"invalidTrafficHaircutMicros",
|
|
4340
|
+
"otherCostMicros",
|
|
4341
|
+
"eligibleNetRevenueMicros",
|
|
4342
|
+
"tokenAmount",
|
|
4343
|
+
"nominalLiabilityMicros",
|
|
4344
|
+
"retainedMarginMicros",
|
|
4345
|
+
"effectiveFrom",
|
|
4346
|
+
"effectiveUntil"
|
|
4347
|
+
]),
|
|
4348
|
+
"Google rewarded-web quote"
|
|
4349
|
+
);
|
|
4350
|
+
economyAssert(
|
|
4351
|
+
quote.schemaVersion === ECONOMY_CONTRACT_VERSION && quote.provider === GOOGLE_REWARDED_WEB_PROVIDER && quote.currency === "GBP",
|
|
4352
|
+
"INVALID_CONTRACT",
|
|
4353
|
+
"Unsupported Google rewarded-web quote contract"
|
|
4354
|
+
);
|
|
4355
|
+
assertEconomyIdentifier(quote.quoteVersion, "quoteVersion");
|
|
4356
|
+
economyAssert(
|
|
4357
|
+
Number.isSafeInteger(quote.bundleCompletions) && quote.bundleCompletions >= 1 && quote.bundleCompletions <= 1e3,
|
|
4358
|
+
"INVALID_CONTRACT",
|
|
4359
|
+
"Bundle completions must be between 1 and 1,000"
|
|
4360
|
+
);
|
|
4361
|
+
assertRewardPayload(quote.rewardPayload);
|
|
4362
|
+
const gross = parseGbpMicros(
|
|
4363
|
+
quote.grossRevenueFloorMicros,
|
|
4364
|
+
"grossRevenueFloorMicros"
|
|
4365
|
+
);
|
|
4366
|
+
const providerFee = parseGbpMicros(
|
|
4367
|
+
quote.providerFeeMicros,
|
|
4368
|
+
"providerFeeMicros"
|
|
4369
|
+
);
|
|
4370
|
+
const invalidTrafficHaircut = parseGbpMicros(
|
|
4371
|
+
quote.invalidTrafficHaircutMicros,
|
|
4372
|
+
"invalidTrafficHaircutMicros"
|
|
4373
|
+
);
|
|
4374
|
+
const otherCost = parseGbpMicros(quote.otherCostMicros, "otherCostMicros");
|
|
4375
|
+
const eligibleNet = parseGbpMicros(
|
|
4376
|
+
quote.eligibleNetRevenueMicros,
|
|
4377
|
+
"eligibleNetRevenueMicros"
|
|
4378
|
+
);
|
|
4379
|
+
const nominalLiability = parseGbpMicros(
|
|
4380
|
+
quote.nominalLiabilityMicros,
|
|
4381
|
+
"nominalLiabilityMicros"
|
|
4382
|
+
);
|
|
4383
|
+
const retainedMargin = parseGbpMicros(
|
|
4384
|
+
quote.retainedMarginMicros,
|
|
4385
|
+
"retainedMarginMicros"
|
|
4386
|
+
);
|
|
4387
|
+
economyAssert(
|
|
4388
|
+
gross === providerFee + invalidTrafficHaircut + otherCost + eligibleNet,
|
|
4389
|
+
"INVALID_CONTRACT",
|
|
4390
|
+
"Rewarded-web quote revenue arithmetic is inconsistent"
|
|
4391
|
+
);
|
|
4392
|
+
economyAssert(
|
|
4393
|
+
parseTokenSubunits(quote.tokenAmount) === TOKEN_SUBUNITS_PER_TOKEN && nominalLiability === GOOGLE_REWARDED_WEB_NOMINAL_MICROS_PER_TOKEN,
|
|
4394
|
+
"INVALID_CONTRACT",
|
|
4395
|
+
"Rewarded-web quote must issue exactly one whole Token"
|
|
4396
|
+
);
|
|
4397
|
+
economyAssert(
|
|
4398
|
+
eligibleNet >= GOOGLE_REWARDED_WEB_MINIMUM_NET_MICROS_PER_TOKEN && retainedMargin === eligibleNet - nominalLiability && retainedMargin * 5n >= eligibleNet,
|
|
4399
|
+
"INVALID_CONTRACT",
|
|
4400
|
+
"Rewarded-web quote does not preserve the 20% contribution margin"
|
|
4401
|
+
);
|
|
4402
|
+
const effectiveFrom = parseIsoTimestamp(quote.effectiveFrom);
|
|
4403
|
+
if (quote.effectiveUntil !== void 0) {
|
|
4404
|
+
economyAssert(
|
|
4405
|
+
parseIsoTimestamp(quote.effectiveUntil) > effectiveFrom,
|
|
4406
|
+
"INVALID_TIME_WINDOW",
|
|
4407
|
+
"Rewarded-web quote expiry must follow its effective time"
|
|
4408
|
+
);
|
|
4409
|
+
}
|
|
4410
|
+
}
|
|
4411
|
+
function assertGoogleRewardedWebGrantClaim(claim) {
|
|
4412
|
+
assertExactKeys4(
|
|
4413
|
+
claim,
|
|
4414
|
+
/* @__PURE__ */ new Set([
|
|
4415
|
+
"schemaVersion",
|
|
4416
|
+
"provider",
|
|
4417
|
+
"evidenceTrust",
|
|
4418
|
+
"claimId",
|
|
4419
|
+
"sessionId",
|
|
4420
|
+
"beneficiaryAccountId",
|
|
4421
|
+
"quoteVersion",
|
|
4422
|
+
"reportingKeyFingerprint",
|
|
4423
|
+
"rewardPayload",
|
|
4424
|
+
"claimedAt"
|
|
4425
|
+
]),
|
|
4426
|
+
"Google rewarded-web grant claim"
|
|
4427
|
+
);
|
|
4428
|
+
economyAssert(
|
|
4429
|
+
claim.schemaVersion === ECONOMY_CONTRACT_VERSION && claim.provider === GOOGLE_REWARDED_WEB_PROVIDER && claim.evidenceTrust === "client-claimed",
|
|
4430
|
+
"INVALID_CONTRACT",
|
|
4431
|
+
"Rewarded-web grant evidence must remain client-claimed"
|
|
4432
|
+
);
|
|
4433
|
+
assertEconomyIdentifier(claim.claimId, "claimId");
|
|
4434
|
+
assertEconomyIdentifier(claim.sessionId, "sessionId");
|
|
4435
|
+
assertEconomyIdentifier(claim.beneficiaryAccountId, "beneficiaryAccountId");
|
|
4436
|
+
assertEconomyIdentifier(claim.quoteVersion, "quoteVersion");
|
|
4437
|
+
assertEconomyHmacFingerprint(
|
|
4438
|
+
claim.reportingKeyFingerprint,
|
|
4439
|
+
"economy.google-reporting-key.v1"
|
|
4440
|
+
);
|
|
4441
|
+
assertRewardPayload(claim.rewardPayload);
|
|
4442
|
+
parseIsoTimestamp(claim.claimedAt);
|
|
4443
|
+
}
|
|
4444
|
+
function assertGoogleRewardedWebReconciliation(reconciliation, quote) {
|
|
4445
|
+
assertGoogleRewardedWebQuote(quote);
|
|
4446
|
+
assertExactKeys4(
|
|
4447
|
+
reconciliation,
|
|
4448
|
+
/* @__PURE__ */ new Set([
|
|
4449
|
+
"schemaVersion",
|
|
4450
|
+
"provider",
|
|
4451
|
+
"batchId",
|
|
4452
|
+
"quoteVersion",
|
|
4453
|
+
"state",
|
|
4454
|
+
"reportFinality",
|
|
4455
|
+
"reportFingerprint",
|
|
4456
|
+
"adUnitFingerprint",
|
|
4457
|
+
"periodStartedAt",
|
|
4458
|
+
"periodEndedAt",
|
|
4459
|
+
"acceptedClaimCount",
|
|
4460
|
+
"matchedPaidImpressionCount",
|
|
4461
|
+
"creditedBundleCount",
|
|
4462
|
+
"grossRevenueMicros",
|
|
4463
|
+
"eligibleNetRevenueMicros",
|
|
4464
|
+
"nominalLiabilityMicros",
|
|
4465
|
+
"reserveHeldMicros",
|
|
4466
|
+
"reconciledAt"
|
|
4467
|
+
]),
|
|
4468
|
+
"Google rewarded-web reconciliation"
|
|
4469
|
+
);
|
|
4470
|
+
economyAssert(
|
|
4471
|
+
reconciliation.schemaVersion === ECONOMY_CONTRACT_VERSION && reconciliation.provider === GOOGLE_REWARDED_WEB_PROVIDER && reconciliation.quoteVersion === quote.quoteVersion && ["report-matched", "financially-reconciled", "mismatch"].includes(
|
|
4472
|
+
reconciliation.state
|
|
4473
|
+
) && ["estimated", "final"].includes(reconciliation.reportFinality),
|
|
4474
|
+
"INVALID_CONTRACT",
|
|
4475
|
+
"Unsupported Google rewarded-web reconciliation contract"
|
|
4476
|
+
);
|
|
4477
|
+
assertEconomyIdentifier(reconciliation.batchId, "batchId");
|
|
4478
|
+
assertEconomyHmacFingerprint(
|
|
4479
|
+
reconciliation.reportFingerprint,
|
|
4480
|
+
"economy.provider-reconciliation.v1"
|
|
4481
|
+
);
|
|
4482
|
+
economyAssert(
|
|
4483
|
+
SHA256.test(reconciliation.adUnitFingerprint),
|
|
4484
|
+
"INVALID_CONTRACT",
|
|
4485
|
+
"Ad-unit fingerprint must be a canonical SHA-256 reference"
|
|
4486
|
+
);
|
|
4487
|
+
const periodStartedAt = parseIsoTimestamp(reconciliation.periodStartedAt);
|
|
4488
|
+
const periodEndedAt = parseIsoTimestamp(reconciliation.periodEndedAt);
|
|
4489
|
+
const reconciledAt = parseIsoTimestamp(reconciliation.reconciledAt);
|
|
4490
|
+
economyAssert(
|
|
4491
|
+
periodEndedAt > periodStartedAt && reconciledAt >= periodEndedAt,
|
|
4492
|
+
"INVALID_TIME_WINDOW",
|
|
4493
|
+
"Reconciliation period and completion times are inconsistent"
|
|
4494
|
+
);
|
|
4495
|
+
assertBoundedCount(reconciliation.acceptedClaimCount, "acceptedClaimCount");
|
|
4496
|
+
assertBoundedCount(
|
|
4497
|
+
reconciliation.matchedPaidImpressionCount,
|
|
4498
|
+
"matchedPaidImpressionCount"
|
|
4499
|
+
);
|
|
4500
|
+
assertBoundedCount(
|
|
4501
|
+
reconciliation.creditedBundleCount,
|
|
4502
|
+
"creditedBundleCount"
|
|
4503
|
+
);
|
|
4504
|
+
const gross = parseGbpMicros(
|
|
4505
|
+
reconciliation.grossRevenueMicros,
|
|
4506
|
+
"grossRevenueMicros"
|
|
4507
|
+
);
|
|
4508
|
+
const eligibleNet = parseGbpMicros(
|
|
4509
|
+
reconciliation.eligibleNetRevenueMicros,
|
|
4510
|
+
"eligibleNetRevenueMicros"
|
|
4511
|
+
);
|
|
4512
|
+
const nominalLiability = parseGbpMicros(
|
|
4513
|
+
reconciliation.nominalLiabilityMicros,
|
|
4514
|
+
"nominalLiabilityMicros"
|
|
4515
|
+
);
|
|
4516
|
+
const reserveHeld = parseGbpMicros(
|
|
4517
|
+
reconciliation.reserveHeldMicros,
|
|
4518
|
+
"reserveHeldMicros"
|
|
4519
|
+
);
|
|
4520
|
+
const expectedCompletions = BigInt(reconciliation.creditedBundleCount) * BigInt(quote.bundleCompletions);
|
|
4521
|
+
const expectedEligibleNet = BigInt(reconciliation.creditedBundleCount) * BigInt(quote.eligibleNetRevenueMicros);
|
|
4522
|
+
const expectedLiability = BigInt(reconciliation.creditedBundleCount) * BigInt(quote.nominalLiabilityMicros);
|
|
4523
|
+
economyAssert(
|
|
4524
|
+
gross >= eligibleNet && nominalLiability === expectedLiability && reserveHeld >= nominalLiability,
|
|
4525
|
+
"INVALID_CONTRACT",
|
|
4526
|
+
"Reconciliation liability or reserve arithmetic is inconsistent"
|
|
4527
|
+
);
|
|
4528
|
+
if (reconciliation.state === "financially-reconciled") {
|
|
4529
|
+
economyAssert(
|
|
4530
|
+
reconciliation.reportFinality === "final" && BigInt(reconciliation.acceptedClaimCount) >= expectedCompletions && BigInt(reconciliation.matchedPaidImpressionCount) >= expectedCompletions && eligibleNet >= expectedEligibleNet,
|
|
4531
|
+
"INVALID_CONTRACT",
|
|
4532
|
+
"Financial reconciliation requires final paid impressions and revenue coverage"
|
|
4533
|
+
);
|
|
4534
|
+
}
|
|
4535
|
+
}
|
|
4536
|
+
var STATE_TRANSITIONS = {
|
|
4537
|
+
created: /* @__PURE__ */ new Set(["bootstrapped", "suspended", "expired"]),
|
|
4538
|
+
bootstrapped: /* @__PURE__ */ new Set(["client-claimed", "suspended", "expired"]),
|
|
4539
|
+
"client-claimed": /* @__PURE__ */ new Set(["report-matched", "suspended", "expired"]),
|
|
4540
|
+
"report-matched": /* @__PURE__ */ new Set([
|
|
4541
|
+
"financially-reconciled",
|
|
4542
|
+
"suspended",
|
|
4543
|
+
"expired"
|
|
4544
|
+
]),
|
|
4545
|
+
"financially-reconciled": /* @__PURE__ */ new Set(),
|
|
4546
|
+
suspended: /* @__PURE__ */ new Set(),
|
|
4547
|
+
expired: /* @__PURE__ */ new Set()
|
|
4548
|
+
};
|
|
4549
|
+
function assertGoogleRewardedWebStateTransition(from, to) {
|
|
4550
|
+
economyAssert(
|
|
4551
|
+
STATE_TRANSITIONS[from]?.has(to) === true,
|
|
4552
|
+
"INVALID_CONTRACT",
|
|
4553
|
+
"Rewarded-web session transition is not forward-safe"
|
|
4554
|
+
);
|
|
4555
|
+
}
|
|
4556
|
+
|
|
4235
4557
|
// src/integrity.ts
|
|
4236
4558
|
function assertCanonicalHash5(value, label) {
|
|
4237
4559
|
economyAssert(
|
|
@@ -4426,6 +4748,7 @@ function assertSourceLot(lot) {
|
|
|
4426
4748
|
"shopify",
|
|
4427
4749
|
"ayet",
|
|
4428
4750
|
"bitlabs",
|
|
4751
|
+
"google-ad-manager",
|
|
4429
4752
|
"subscription",
|
|
4430
4753
|
"event",
|
|
4431
4754
|
"competition",
|
|
@@ -4448,7 +4771,7 @@ function assertSourceLot(lot) {
|
|
|
4448
4771
|
"INVALID_CONTRACT",
|
|
4449
4772
|
"Source lot has an unsupported refund state"
|
|
4450
4773
|
);
|
|
4451
|
-
if (lot.source === "ayet" || lot.source === "bitlabs") {
|
|
4774
|
+
if (lot.source === "ayet" || lot.source === "bitlabs" || lot.source === "google-ad-manager") {
|
|
4452
4775
|
economyAssert(
|
|
4453
4776
|
lot.transferPolicy === "same-user-only" && lot.providerEventId !== void 0,
|
|
4454
4777
|
"SOURCE_LOT_RESTRICTED",
|
|
@@ -5542,7 +5865,7 @@ var DECISIONS = /* @__PURE__ */ new Set([
|
|
|
5542
5865
|
"approve",
|
|
5543
5866
|
"reject"
|
|
5544
5867
|
]);
|
|
5545
|
-
function
|
|
5868
|
+
function assertExactKeys5(value, allowed, label) {
|
|
5546
5869
|
economyAssert(
|
|
5547
5870
|
value !== null && typeof value === "object" && !Array.isArray(value),
|
|
5548
5871
|
"INVALID_CONTRACT",
|
|
@@ -5569,7 +5892,7 @@ function assertReasonCode(reasonCode) {
|
|
|
5569
5892
|
);
|
|
5570
5893
|
}
|
|
5571
5894
|
function assertOperatorAdjustmentPreview(preview) {
|
|
5572
|
-
|
|
5895
|
+
assertExactKeys5(preview, PREVIEW_KEYS, "Operator adjustment preview");
|
|
5573
5896
|
economyAssert(
|
|
5574
5897
|
preview.schemaVersion === ECONOMY_CONTRACT_VERSION && OPERATIONS.has(preview.operation) && TARGET_COMPONENTS.has(preview.targetComponent) && TRANSFER_POLICIES.has(preview.transferPolicy) && preview.refundPolicy === "not-refundable",
|
|
5575
5898
|
"INVALID_CONTRACT",
|
|
@@ -5648,7 +5971,7 @@ function canonicalOperatorAdjustmentPreviewPayload(preview) {
|
|
|
5648
5971
|
function assertOperatorAdjustmentProposal(proposal, preview, expectedPreviewHash) {
|
|
5649
5972
|
assertOperatorAdjustmentPreview(preview);
|
|
5650
5973
|
assertCanonicalHash6(expectedPreviewHash, "expectedPreviewHash");
|
|
5651
|
-
|
|
5974
|
+
assertExactKeys5(proposal, PROPOSAL_KEYS, "Operator adjustment proposal");
|
|
5652
5975
|
economyAssert(
|
|
5653
5976
|
proposal.schemaVersion === ECONOMY_CONTRACT_VERSION && proposal.status === "pending-approval",
|
|
5654
5977
|
"INVALID_CONTRACT",
|
|
@@ -5675,7 +5998,7 @@ function assertOperatorAdjustmentProposal(proposal, preview, expectedPreviewHash
|
|
|
5675
5998
|
);
|
|
5676
5999
|
}
|
|
5677
6000
|
function canonicalOperatorAdjustmentProposalPayload(proposal) {
|
|
5678
|
-
|
|
6001
|
+
assertExactKeys5(proposal, PROPOSAL_KEYS, "Operator adjustment proposal");
|
|
5679
6002
|
return JSON.stringify({
|
|
5680
6003
|
schemaVersion: proposal.schemaVersion,
|
|
5681
6004
|
proposalId: proposal.proposalId,
|
|
@@ -5690,7 +6013,7 @@ function canonicalOperatorAdjustmentProposalPayload(proposal) {
|
|
|
5690
6013
|
function assertOperatorAdjustmentDecision(decision, proposal, preview, expectedPreviewHash, expectedProposalHash) {
|
|
5691
6014
|
assertOperatorAdjustmentProposal(proposal, preview, expectedPreviewHash);
|
|
5692
6015
|
assertCanonicalHash6(expectedProposalHash, "expectedProposalHash");
|
|
5693
|
-
|
|
6016
|
+
assertExactKeys5(decision, DECISION_KEYS, "Operator adjustment decision");
|
|
5694
6017
|
economyAssert(
|
|
5695
6018
|
decision.schemaVersion === ECONOMY_CONTRACT_VERSION && DECISIONS.has(decision.decision),
|
|
5696
6019
|
"INVALID_CONTRACT",
|
|
@@ -5733,7 +6056,7 @@ function assertOperatorAdjustmentDecision(decision, proposal, preview, expectedP
|
|
|
5733
6056
|
);
|
|
5734
6057
|
}
|
|
5735
6058
|
function canonicalOperatorAdjustmentDecisionPayload(decision) {
|
|
5736
|
-
|
|
6059
|
+
assertExactKeys5(decision, DECISION_KEYS, "Operator adjustment decision");
|
|
5737
6060
|
return JSON.stringify({
|
|
5738
6061
|
schemaVersion: decision.schemaVersion,
|
|
5739
6062
|
decisionId: decision.decisionId,
|
|
@@ -5757,7 +6080,7 @@ function assertOperatorAdjustmentExecution(execution, preview, proposal, decisio
|
|
|
5757
6080
|
expectedProposalHash
|
|
5758
6081
|
);
|
|
5759
6082
|
assertCanonicalHash6(expectedDecisionHash, "expectedDecisionHash");
|
|
5760
|
-
|
|
6083
|
+
assertExactKeys5(execution, EXECUTION_KEYS, "Operator adjustment execution");
|
|
5761
6084
|
economyAssert(
|
|
5762
6085
|
execution.schemaVersion === ECONOMY_CONTRACT_VERSION,
|
|
5763
6086
|
"INVALID_CONTRACT",
|
|
@@ -5788,7 +6111,7 @@ function assertOperatorAdjustmentExecution(execution, preview, proposal, decisio
|
|
|
5788
6111
|
);
|
|
5789
6112
|
}
|
|
5790
6113
|
function canonicalOperatorAdjustmentExecutionPayload(execution) {
|
|
5791
|
-
|
|
6114
|
+
assertExactKeys5(execution, EXECUTION_KEYS, "Operator adjustment execution");
|
|
5792
6115
|
return JSON.stringify({
|
|
5793
6116
|
schemaVersion: execution.schemaVersion,
|
|
5794
6117
|
executionId: execution.executionId,
|
|
@@ -6861,6 +7184,7 @@ var ACTIVITY_SOURCES3 = /* @__PURE__ */ new Set([
|
|
|
6861
7184
|
"shopify",
|
|
6862
7185
|
"ayet",
|
|
6863
7186
|
"bitlabs",
|
|
7187
|
+
"google-ad-manager",
|
|
6864
7188
|
"subscription",
|
|
6865
7189
|
"event",
|
|
6866
7190
|
"competition",
|
|
@@ -8343,7 +8667,7 @@ var PORTABLE_KEYS = /* @__PURE__ */ new Set([
|
|
|
8343
8667
|
"signature",
|
|
8344
8668
|
...PORTABLE_BODY_KEYS
|
|
8345
8669
|
]);
|
|
8346
|
-
function
|
|
8670
|
+
function assertExactKeys6(value, allowedKeys, label) {
|
|
8347
8671
|
economyAssert(
|
|
8348
8672
|
value !== null && typeof value === "object" && !Array.isArray(value),
|
|
8349
8673
|
"INVALID_CONTRACT",
|
|
@@ -8432,7 +8756,7 @@ function canonicalSignatureMetadata(signature) {
|
|
|
8432
8756
|
};
|
|
8433
8757
|
}
|
|
8434
8758
|
function assertEconomySealedRecoveryPayload(payload) {
|
|
8435
|
-
|
|
8759
|
+
assertExactKeys6(
|
|
8436
8760
|
payload,
|
|
8437
8761
|
/* @__PURE__ */ new Set([
|
|
8438
8762
|
"schemaVersion",
|
|
@@ -8472,7 +8796,7 @@ function assertEconomySealedRecoveryPayload(payload) {
|
|
|
8472
8796
|
);
|
|
8473
8797
|
}
|
|
8474
8798
|
function assertAcceptanceBody(body) {
|
|
8475
|
-
|
|
8799
|
+
assertExactKeys6(
|
|
8476
8800
|
body,
|
|
8477
8801
|
"acceptanceEnvelopeId" in body ? ACCEPTANCE_KEYS : ACCEPTANCE_BODY_KEYS,
|
|
8478
8802
|
"Recovery acceptance body"
|
|
@@ -8541,7 +8865,7 @@ function createEconomyRecoveryAcceptanceEnvelope(body, hashCanonicalPayload2) {
|
|
|
8541
8865
|
};
|
|
8542
8866
|
}
|
|
8543
8867
|
function assertEconomyRecoveryAcceptanceEnvelope(envelope, hashCanonicalPayload2) {
|
|
8544
|
-
|
|
8868
|
+
assertExactKeys6(envelope, ACCEPTANCE_KEYS, "Recovery acceptance envelope");
|
|
8545
8869
|
assertAcceptanceBody(envelope);
|
|
8546
8870
|
assertEconomyIdentifier(
|
|
8547
8871
|
envelope.acceptanceEnvelopeId,
|
|
@@ -8582,7 +8906,7 @@ function canonicalEconomyRecoveryAcceptanceEnvelopePayload(envelope, hashCanonic
|
|
|
8582
8906
|
});
|
|
8583
8907
|
}
|
|
8584
8908
|
function assertCommittedResultBody(body) {
|
|
8585
|
-
|
|
8909
|
+
assertExactKeys6(
|
|
8586
8910
|
body,
|
|
8587
8911
|
"committedResultId" in body ? COMMITTED_RESULT_KEYS : COMMITTED_RESULT_BODY_KEYS,
|
|
8588
8912
|
"Recovery committed-result body"
|
|
@@ -8676,7 +9000,7 @@ function createEconomyRecoveryCommittedResult(body, hashCanonicalPayload2) {
|
|
|
8676
9000
|
};
|
|
8677
9001
|
}
|
|
8678
9002
|
function assertEconomyRecoveryCommittedResult(result, hashCanonicalPayload2) {
|
|
8679
|
-
|
|
9003
|
+
assertExactKeys6(
|
|
8680
9004
|
result,
|
|
8681
9005
|
COMMITTED_RESULT_KEYS,
|
|
8682
9006
|
"Recovery committed result"
|
|
@@ -8735,7 +9059,7 @@ function assertEconomyRecoveryResultLink(acceptance, result, hashCanonicalPayloa
|
|
|
8735
9059
|
);
|
|
8736
9060
|
}
|
|
8737
9061
|
function assertEconomyEvidenceSignatureMetadata(signature) {
|
|
8738
|
-
|
|
9062
|
+
assertExactKeys6(
|
|
8739
9063
|
signature,
|
|
8740
9064
|
/* @__PURE__ */ new Set([
|
|
8741
9065
|
"schemaVersion",
|
|
@@ -8755,7 +9079,7 @@ function assertEconomyEvidenceSignatureMetadata(signature) {
|
|
|
8755
9079
|
parseIsoTimestamp(signature.signedAt);
|
|
8756
9080
|
}
|
|
8757
9081
|
function assertEconomyEvidenceSignature(signature) {
|
|
8758
|
-
|
|
9082
|
+
assertExactKeys6(
|
|
8759
9083
|
signature,
|
|
8760
9084
|
/* @__PURE__ */ new Set([
|
|
8761
9085
|
"schemaVersion",
|
|
@@ -8777,7 +9101,7 @@ function assertEconomyEvidenceSignature(signature) {
|
|
|
8777
9101
|
assertBase64url(signature.value, "Evidence signature value", 32, 2048);
|
|
8778
9102
|
}
|
|
8779
9103
|
function assertRegionalEvidenceBody(body) {
|
|
8780
|
-
|
|
9104
|
+
assertExactKeys6(
|
|
8781
9105
|
body,
|
|
8782
9106
|
"evidenceReceiptId" in body ? REGIONAL_KEYS : REGIONAL_BODY_KEYS,
|
|
8783
9107
|
"Regional evidence-receipt body"
|
|
@@ -8869,7 +9193,7 @@ function createEconomyRegionalEvidenceReceipt(body, signature, hashCanonicalPayl
|
|
|
8869
9193
|
};
|
|
8870
9194
|
}
|
|
8871
9195
|
function assertEconomyRegionalEvidenceReceipt(receipt, hashCanonicalPayload2) {
|
|
8872
|
-
|
|
9196
|
+
assertExactKeys6(receipt, REGIONAL_KEYS, "Regional evidence receipt");
|
|
8873
9197
|
assertRegionalEvidenceBody(receipt);
|
|
8874
9198
|
assertEconomyIdentifier(receipt.evidenceReceiptId, "evidenceReceiptId");
|
|
8875
9199
|
assertEconomyEvidenceSignature(receipt.signature);
|
|
@@ -9071,7 +9395,7 @@ function assertEconomyRegionalEvidenceEquality(receipts, expectedRegions, hashCa
|
|
|
9071
9395
|
);
|
|
9072
9396
|
}
|
|
9073
9397
|
function assertEconomyMerkleInclusionProof(proof) {
|
|
9074
|
-
|
|
9398
|
+
assertExactKeys6(
|
|
9075
9399
|
proof,
|
|
9076
9400
|
/* @__PURE__ */ new Set([
|
|
9077
9401
|
"schemaVersion",
|
|
@@ -9102,7 +9426,7 @@ function assertEconomyMerkleInclusionProof(proof) {
|
|
|
9102
9426
|
"Merkle leaf position is outside its bounded tree"
|
|
9103
9427
|
);
|
|
9104
9428
|
for (const step of proof.siblings) {
|
|
9105
|
-
|
|
9429
|
+
assertExactKeys6(
|
|
9106
9430
|
step,
|
|
9107
9431
|
/* @__PURE__ */ new Set(["schemaVersion", "side", "hash"]),
|
|
9108
9432
|
"Merkle proof step"
|
|
@@ -9191,7 +9515,7 @@ function assertEconomyMerkleInclusion(proof, anchor, hashCanonicalPayload2) {
|
|
|
9191
9515
|
);
|
|
9192
9516
|
}
|
|
9193
9517
|
function assertPortableEvidenceReference(reference) {
|
|
9194
|
-
|
|
9518
|
+
assertExactKeys6(
|
|
9195
9519
|
reference,
|
|
9196
9520
|
/* @__PURE__ */ new Set([
|
|
9197
9521
|
"schemaVersion",
|
|
@@ -9228,7 +9552,7 @@ function canonicalPortableEvidenceReference(reference) {
|
|
|
9228
9552
|
};
|
|
9229
9553
|
}
|
|
9230
9554
|
function assertPortableBody(body) {
|
|
9231
|
-
|
|
9555
|
+
assertExactKeys6(
|
|
9232
9556
|
body,
|
|
9233
9557
|
"portableReceiptId" in body ? PORTABLE_KEYS : PORTABLE_BODY_KEYS,
|
|
9234
9558
|
"Portable customer-receipt body"
|
|
@@ -9352,7 +9676,7 @@ function createEconomyPortableCustomerReceipt(body, signature, hashCanonicalPayl
|
|
|
9352
9676
|
};
|
|
9353
9677
|
}
|
|
9354
9678
|
function assertEconomyPortableCustomerReceipt(receipt, hashCanonicalPayload2) {
|
|
9355
|
-
|
|
9679
|
+
assertExactKeys6(receipt, PORTABLE_KEYS, "Portable customer receipt");
|
|
9356
9680
|
assertPortableBody(receipt);
|
|
9357
9681
|
assertEconomyIdentifier(receipt.portableReceiptId, "portableReceiptId");
|
|
9358
9682
|
assertEconomyEvidenceSignature(receipt.signature);
|
|
@@ -9652,7 +9976,7 @@ var DOCUMENT_ID_KEYS = /* @__PURE__ */ new Set([
|
|
|
9652
9976
|
"lifetimeProjectionId",
|
|
9653
9977
|
"outboxEventId"
|
|
9654
9978
|
]);
|
|
9655
|
-
function
|
|
9979
|
+
function assertExactKeys7(value, allowed, label) {
|
|
9656
9980
|
economyAssert(
|
|
9657
9981
|
value !== null && typeof value === "object" && !Array.isArray(value),
|
|
9658
9982
|
"INVALID_CONTRACT",
|
|
@@ -9692,7 +10016,7 @@ function createPersonalWalletInitializationDocumentIds(subjectAccountId, hash) {
|
|
|
9692
10016
|
};
|
|
9693
10017
|
}
|
|
9694
10018
|
function assertPersonalWalletInitializationCommand(command) {
|
|
9695
|
-
|
|
10019
|
+
assertExactKeys7(command, COMMAND_KEYS, "Wallet initialization command");
|
|
9696
10020
|
economyAssert(
|
|
9697
10021
|
command.schemaVersion === ECONOMY_CONTRACT_VERSION && command.commandType === "initialize-wallet" && command.walletKind === "personal",
|
|
9698
10022
|
"INVALID_CONTRACT",
|
|
@@ -9716,7 +10040,7 @@ function canonicalPersonalWalletInitializationCommandPayload(command) {
|
|
|
9716
10040
|
});
|
|
9717
10041
|
}
|
|
9718
10042
|
function assertPersonalWalletInitializationOutboxIntent(intent) {
|
|
9719
|
-
|
|
10043
|
+
assertExactKeys7(intent, OUTBOX_KEYS, "Wallet initialization outbox intent");
|
|
9720
10044
|
economyAssert(
|
|
9721
10045
|
intent.schemaVersion === ECONOMY_CONTRACT_VERSION && intent.eventType === "wallet.initialized.v1",
|
|
9722
10046
|
"INVALID_CONTRACT",
|
|
@@ -9816,8 +10140,8 @@ function createPersonalWalletInitializationState(input, hash) {
|
|
|
9816
10140
|
return state;
|
|
9817
10141
|
}
|
|
9818
10142
|
function assertPersonalWalletInitializationState(state) {
|
|
9819
|
-
|
|
9820
|
-
|
|
10143
|
+
assertExactKeys7(state, STATE_KEYS, "Wallet initialization state");
|
|
10144
|
+
assertExactKeys7(
|
|
9821
10145
|
state.documentIds,
|
|
9822
10146
|
DOCUMENT_ID_KEYS,
|
|
9823
10147
|
"Wallet initialization document IDs"
|
|
@@ -9868,6 +10192,9 @@ export {
|
|
|
9868
10192
|
ECONOMY_CONTRACT_VERSION,
|
|
9869
10193
|
ECONOMY_RECOVERY_PROTOCOL_VERSION,
|
|
9870
10194
|
EconomyError,
|
|
10195
|
+
GOOGLE_REWARDED_WEB_MINIMUM_NET_MICROS_PER_TOKEN,
|
|
10196
|
+
GOOGLE_REWARDED_WEB_NOMINAL_MICROS_PER_TOKEN,
|
|
10197
|
+
GOOGLE_REWARDED_WEB_PROVIDER,
|
|
9871
10198
|
MODULE_ALLOWANCE_PURPOSE,
|
|
9872
10199
|
PRE_UTILITY_BACKER_COHORT,
|
|
9873
10200
|
TOKEN_SUBUNITS_MAX,
|
|
@@ -9940,6 +10267,10 @@ export {
|
|
|
9940
10267
|
assertFlatTokenCatalog,
|
|
9941
10268
|
assertFxSnapshot,
|
|
9942
10269
|
assertGameplayAllocation,
|
|
10270
|
+
assertGoogleRewardedWebGrantClaim,
|
|
10271
|
+
assertGoogleRewardedWebQuote,
|
|
10272
|
+
assertGoogleRewardedWebReconciliation,
|
|
10273
|
+
assertGoogleRewardedWebStateTransition,
|
|
9943
10274
|
assertJournalChainHead,
|
|
9944
10275
|
assertModuleAllowance,
|
|
9945
10276
|
assertModulePurchaseReceipt,
|
|
@@ -10033,6 +10364,7 @@ export {
|
|
|
10033
10364
|
createEconomyRecoveryCommittedResult,
|
|
10034
10365
|
createEconomyRegionalEvidenceReceipt,
|
|
10035
10366
|
createGameplayAllocation,
|
|
10367
|
+
createGoogleRewardedWebQuote,
|
|
10036
10368
|
createInitialSourceLotSnapshot,
|
|
10037
10369
|
createModuleAllowance,
|
|
10038
10370
|
createModulePurchaseReceipt,
|