@invisi-labs/protocol 1.1.1 → 1.1.3
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/dist/index.cjs +173 -33
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +18 -2
- package/dist/index.d.ts +18 -2
- package/dist/index.js +176 -33
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
package/dist/index.d.cts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import * as _invisi_labs_core from '@invisi-labs/core';
|
|
1
2
|
import { Hex, Address, ReceivingKeyLookup, Wallet, Note, CreditDeliveryState, AuthorizedStatement } from '@invisi-labs/core';
|
|
2
3
|
import { ContractRunner, Signer, Provider } from 'ethers';
|
|
3
4
|
import { DeploymentContext, CanonicalBlock, ProtocolDeployment, ProtocolRpcClient } from '@invisi-labs/rpc';
|
|
@@ -67,6 +68,8 @@ declare function createRegistryReceivingKeyLookup(client: RegistryReadClient, re
|
|
|
67
68
|
interface TransactionContext extends DeploymentContext {
|
|
68
69
|
tokenAddress: Address;
|
|
69
70
|
now?: bigint;
|
|
71
|
+
/** Explicit chain timestamp used to bind Credit draw UTC periods. */
|
|
72
|
+
timestamp?: bigint;
|
|
70
73
|
}
|
|
71
74
|
declare const FIELD_MODULUS = 21888242871839275222246405745257275088548364400416034343698204186575808495617n;
|
|
72
75
|
declare const ZERO_ADDRESS: "0x0000000000000000000000000000000000000000";
|
|
@@ -87,12 +90,14 @@ declare const word: (v: bigint | string) => Hex;
|
|
|
87
90
|
declare function dense<T>(v: readonly T[], name: string): readonly T[];
|
|
88
91
|
declare function known(v: object, keys: readonly string[], name?: string): void;
|
|
89
92
|
declare function notes(v: readonly Hex[], name: string): `0x${string}`[];
|
|
90
|
-
declare function envelope(v: Hex, length: number, version?: number): Hex;
|
|
93
|
+
declare function envelope(v: Hex, length: number, version?: number, maximum?: number): Hex;
|
|
91
94
|
declare function normalizeContext(c: TransactionContext): {
|
|
92
95
|
chainId: bigint;
|
|
93
96
|
protocolAddress: Hex;
|
|
94
97
|
tokenAddress: Hex;
|
|
95
98
|
now?: bigint;
|
|
99
|
+
/** Explicit chain timestamp used to bind Credit draw UTC periods. */
|
|
100
|
+
timestamp?: bigint;
|
|
96
101
|
};
|
|
97
102
|
declare function checkDeadline(c: TransactionContext, value: bigint): bigint;
|
|
98
103
|
declare function normalizeSources(sources: readonly InputSource[], inputCount: number, capacity: number): {
|
|
@@ -307,6 +312,7 @@ declare function validateCreateCreditRequest(c: TransactionContext, p: CreateCre
|
|
|
307
312
|
protocolAddress: Hex;
|
|
308
313
|
tokenAddress: Hex;
|
|
309
314
|
now?: bigint;
|
|
315
|
+
timestamp?: bigint;
|
|
310
316
|
};
|
|
311
317
|
declare function createCreditBaseInputs(c: TransactionContext, p: CreateCreditParams, cs: readonly Delivery[], f?: FundingInput): `0x${string}`[];
|
|
312
318
|
declare function createCreditPublicInputs(c: TransactionContext, p: CreateCreditParams, deliveries: readonly Delivery[], funding?: FundingInput): `0x${string}`[];
|
|
@@ -408,10 +414,15 @@ declare function validateCreditDrawRequest(c: TransactionContext, p: CreditDrawP
|
|
|
408
414
|
publicInputCount: number;
|
|
409
415
|
totalBits: number;
|
|
410
416
|
};
|
|
417
|
+
periods: {
|
|
418
|
+
currentDay: bigint;
|
|
419
|
+
currentMonth: bigint;
|
|
420
|
+
};
|
|
411
421
|
chainId: bigint;
|
|
412
422
|
protocolAddress: Hex;
|
|
413
423
|
tokenAddress: Hex;
|
|
414
424
|
now?: bigint;
|
|
425
|
+
timestamp?: bigint;
|
|
415
426
|
};
|
|
416
427
|
declare function creditDrawBaseInputs(c: TransactionContext, p: CreditDrawParams, cs: readonly Delivery[]): `0x${string}`[];
|
|
417
428
|
declare function validateCancelCreditRequest(c: TransactionContext, p: CancelCreditParams): {
|
|
@@ -427,6 +438,7 @@ declare function validateCancelCreditRequest(c: TransactionContext, p: CancelCre
|
|
|
427
438
|
protocolAddress: Hex;
|
|
428
439
|
tokenAddress: Hex;
|
|
429
440
|
now?: bigint;
|
|
441
|
+
timestamp?: bigint;
|
|
430
442
|
};
|
|
431
443
|
declare function cancelCreditBaseInputs(c: TransactionContext, p: CancelCreditParams): `0x${string}`[];
|
|
432
444
|
declare function validateTopUpCreditRequest(c: TransactionContext, p: TopUpCreditParams, cs: readonly Delivery[], funding?: FundingInput): {
|
|
@@ -449,6 +461,7 @@ declare function validateTopUpCreditRequest(c: TransactionContext, p: TopUpCredi
|
|
|
449
461
|
protocolAddress: Hex;
|
|
450
462
|
tokenAddress: Hex;
|
|
451
463
|
now?: bigint;
|
|
464
|
+
timestamp?: bigint;
|
|
452
465
|
};
|
|
453
466
|
creditSource: {
|
|
454
467
|
treeId: bigint;
|
|
@@ -625,6 +638,7 @@ declare function normalizeTransactRequest(c: TransactionContext, p: TransactRequ
|
|
|
625
638
|
protocolAddress: Hex;
|
|
626
639
|
tokenAddress: Hex;
|
|
627
640
|
now?: bigint;
|
|
641
|
+
timestamp?: bigint;
|
|
628
642
|
};
|
|
629
643
|
declare function transactPublicInputs(c: TransactionContext, p: TransactRequestParams, cs: readonly Delivery[], f?: FundingInput): `0x${string}`[];
|
|
630
644
|
declare function encodeTransactTypedData(c: TransactionContext, p: TransactRequestParams, deliveries: readonly Delivery[], f?: FundingInput): {
|
|
@@ -892,7 +906,7 @@ interface VerifyNoteCommitmentParams {
|
|
|
892
906
|
chainId: bigint;
|
|
893
907
|
}
|
|
894
908
|
declare function verifyNoteCommitment(params: VerifyNoteCommitmentParams): Promise<boolean>;
|
|
895
|
-
interface VerifyCreditCommitmentParams {
|
|
909
|
+
interface VerifyCreditCommitmentParams extends Partial<_invisi_labs_core.CreditPolicy> {
|
|
896
910
|
chainId: bigint;
|
|
897
911
|
spenderWalletIdentity: `0x${string}`;
|
|
898
912
|
ownerWalletIdentity: `0x${string}`;
|
|
@@ -951,6 +965,8 @@ interface CreateCreditWitnessParams {
|
|
|
951
965
|
authorization: AuthorizedStatement;
|
|
952
966
|
}
|
|
953
967
|
interface DrawCreditWitnessParams {
|
|
968
|
+
/** Explicit chain timestamp used to prepare this signed statement. */
|
|
969
|
+
timestamp: bigint;
|
|
954
970
|
params: CreditDrawParams;
|
|
955
971
|
deliveries: readonly Delivery[];
|
|
956
972
|
inputs: readonly CreditMembership[];
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import * as _invisi_labs_core from '@invisi-labs/core';
|
|
1
2
|
import { Hex, Address, ReceivingKeyLookup, Wallet, Note, CreditDeliveryState, AuthorizedStatement } from '@invisi-labs/core';
|
|
2
3
|
import { ContractRunner, Signer, Provider } from 'ethers';
|
|
3
4
|
import { DeploymentContext, CanonicalBlock, ProtocolDeployment, ProtocolRpcClient } from '@invisi-labs/rpc';
|
|
@@ -67,6 +68,8 @@ declare function createRegistryReceivingKeyLookup(client: RegistryReadClient, re
|
|
|
67
68
|
interface TransactionContext extends DeploymentContext {
|
|
68
69
|
tokenAddress: Address;
|
|
69
70
|
now?: bigint;
|
|
71
|
+
/** Explicit chain timestamp used to bind Credit draw UTC periods. */
|
|
72
|
+
timestamp?: bigint;
|
|
70
73
|
}
|
|
71
74
|
declare const FIELD_MODULUS = 21888242871839275222246405745257275088548364400416034343698204186575808495617n;
|
|
72
75
|
declare const ZERO_ADDRESS: "0x0000000000000000000000000000000000000000";
|
|
@@ -87,12 +90,14 @@ declare const word: (v: bigint | string) => Hex;
|
|
|
87
90
|
declare function dense<T>(v: readonly T[], name: string): readonly T[];
|
|
88
91
|
declare function known(v: object, keys: readonly string[], name?: string): void;
|
|
89
92
|
declare function notes(v: readonly Hex[], name: string): `0x${string}`[];
|
|
90
|
-
declare function envelope(v: Hex, length: number, version?: number): Hex;
|
|
93
|
+
declare function envelope(v: Hex, length: number, version?: number, maximum?: number): Hex;
|
|
91
94
|
declare function normalizeContext(c: TransactionContext): {
|
|
92
95
|
chainId: bigint;
|
|
93
96
|
protocolAddress: Hex;
|
|
94
97
|
tokenAddress: Hex;
|
|
95
98
|
now?: bigint;
|
|
99
|
+
/** Explicit chain timestamp used to bind Credit draw UTC periods. */
|
|
100
|
+
timestamp?: bigint;
|
|
96
101
|
};
|
|
97
102
|
declare function checkDeadline(c: TransactionContext, value: bigint): bigint;
|
|
98
103
|
declare function normalizeSources(sources: readonly InputSource[], inputCount: number, capacity: number): {
|
|
@@ -307,6 +312,7 @@ declare function validateCreateCreditRequest(c: TransactionContext, p: CreateCre
|
|
|
307
312
|
protocolAddress: Hex;
|
|
308
313
|
tokenAddress: Hex;
|
|
309
314
|
now?: bigint;
|
|
315
|
+
timestamp?: bigint;
|
|
310
316
|
};
|
|
311
317
|
declare function createCreditBaseInputs(c: TransactionContext, p: CreateCreditParams, cs: readonly Delivery[], f?: FundingInput): `0x${string}`[];
|
|
312
318
|
declare function createCreditPublicInputs(c: TransactionContext, p: CreateCreditParams, deliveries: readonly Delivery[], funding?: FundingInput): `0x${string}`[];
|
|
@@ -408,10 +414,15 @@ declare function validateCreditDrawRequest(c: TransactionContext, p: CreditDrawP
|
|
|
408
414
|
publicInputCount: number;
|
|
409
415
|
totalBits: number;
|
|
410
416
|
};
|
|
417
|
+
periods: {
|
|
418
|
+
currentDay: bigint;
|
|
419
|
+
currentMonth: bigint;
|
|
420
|
+
};
|
|
411
421
|
chainId: bigint;
|
|
412
422
|
protocolAddress: Hex;
|
|
413
423
|
tokenAddress: Hex;
|
|
414
424
|
now?: bigint;
|
|
425
|
+
timestamp?: bigint;
|
|
415
426
|
};
|
|
416
427
|
declare function creditDrawBaseInputs(c: TransactionContext, p: CreditDrawParams, cs: readonly Delivery[]): `0x${string}`[];
|
|
417
428
|
declare function validateCancelCreditRequest(c: TransactionContext, p: CancelCreditParams): {
|
|
@@ -427,6 +438,7 @@ declare function validateCancelCreditRequest(c: TransactionContext, p: CancelCre
|
|
|
427
438
|
protocolAddress: Hex;
|
|
428
439
|
tokenAddress: Hex;
|
|
429
440
|
now?: bigint;
|
|
441
|
+
timestamp?: bigint;
|
|
430
442
|
};
|
|
431
443
|
declare function cancelCreditBaseInputs(c: TransactionContext, p: CancelCreditParams): `0x${string}`[];
|
|
432
444
|
declare function validateTopUpCreditRequest(c: TransactionContext, p: TopUpCreditParams, cs: readonly Delivery[], funding?: FundingInput): {
|
|
@@ -449,6 +461,7 @@ declare function validateTopUpCreditRequest(c: TransactionContext, p: TopUpCredi
|
|
|
449
461
|
protocolAddress: Hex;
|
|
450
462
|
tokenAddress: Hex;
|
|
451
463
|
now?: bigint;
|
|
464
|
+
timestamp?: bigint;
|
|
452
465
|
};
|
|
453
466
|
creditSource: {
|
|
454
467
|
treeId: bigint;
|
|
@@ -625,6 +638,7 @@ declare function normalizeTransactRequest(c: TransactionContext, p: TransactRequ
|
|
|
625
638
|
protocolAddress: Hex;
|
|
626
639
|
tokenAddress: Hex;
|
|
627
640
|
now?: bigint;
|
|
641
|
+
timestamp?: bigint;
|
|
628
642
|
};
|
|
629
643
|
declare function transactPublicInputs(c: TransactionContext, p: TransactRequestParams, cs: readonly Delivery[], f?: FundingInput): `0x${string}`[];
|
|
630
644
|
declare function encodeTransactTypedData(c: TransactionContext, p: TransactRequestParams, deliveries: readonly Delivery[], f?: FundingInput): {
|
|
@@ -892,7 +906,7 @@ interface VerifyNoteCommitmentParams {
|
|
|
892
906
|
chainId: bigint;
|
|
893
907
|
}
|
|
894
908
|
declare function verifyNoteCommitment(params: VerifyNoteCommitmentParams): Promise<boolean>;
|
|
895
|
-
interface VerifyCreditCommitmentParams {
|
|
909
|
+
interface VerifyCreditCommitmentParams extends Partial<_invisi_labs_core.CreditPolicy> {
|
|
896
910
|
chainId: bigint;
|
|
897
911
|
spenderWalletIdentity: `0x${string}`;
|
|
898
912
|
ownerWalletIdentity: `0x${string}`;
|
|
@@ -951,6 +965,8 @@ interface CreateCreditWitnessParams {
|
|
|
951
965
|
authorization: AuthorizedStatement;
|
|
952
966
|
}
|
|
953
967
|
interface DrawCreditWitnessParams {
|
|
968
|
+
/** Explicit chain timestamp used to prepare this signed statement. */
|
|
969
|
+
timestamp: bigint;
|
|
954
970
|
params: CreditDrawParams;
|
|
955
971
|
deliveries: readonly Delivery[];
|
|
956
972
|
inputs: readonly CreditMembership[];
|
package/dist/index.js
CHANGED
|
@@ -572,8 +572,8 @@ function notes(v, name) {
|
|
|
572
572
|
throw new Error(`duplicate or zero ${name}`);
|
|
573
573
|
return r;
|
|
574
574
|
}
|
|
575
|
-
function envelope(v, length, version) {
|
|
576
|
-
if (!isHexString2(v) || !/^0x(?:[a-fA-F0-9]{2})*$/.test(v) || dataLength(v)
|
|
575
|
+
function envelope(v, length, version, maximum = length) {
|
|
576
|
+
if (!isHexString2(v) || !/^0x(?:[a-fA-F0-9]{2})*$/.test(v) || dataLength(v) < length || dataLength(v) > maximum)
|
|
577
577
|
throw new Error(`ciphertext must be ${length} bytes`);
|
|
578
578
|
if (version !== void 0 && Number.parseInt(v.slice(2, 4), 16) !== version)
|
|
579
579
|
throw new Error("unsupported ciphertext envelope version");
|
|
@@ -619,8 +619,9 @@ function normalizeDelivery(value, options = {}) {
|
|
|
619
619
|
}
|
|
620
620
|
const ciphertext = envelope(
|
|
621
621
|
value.ciphertext,
|
|
622
|
-
options.credit ?
|
|
623
|
-
options.credit ?
|
|
622
|
+
options.credit ? 498 : 160,
|
|
623
|
+
options.credit ? 5 : 2,
|
|
624
|
+
options.credit ? 754 : 416
|
|
624
625
|
);
|
|
625
626
|
const clue = envelope(value.clue, 68);
|
|
626
627
|
if (clue.slice(130, 132).toLowerCase() !== "18") throw new Error("clue precision must be 24");
|
|
@@ -838,6 +839,7 @@ function encodeCreditProof(proof) {
|
|
|
838
839
|
// src/credit-lifecycle.ts
|
|
839
840
|
import { AbiCoder as AbiCoder3, getAddress as getAddress5, Interface as Interface4, keccak256 as keccak2564, ParamType as ParamType3 } from "ethers";
|
|
840
841
|
import {
|
|
842
|
+
creditPeriods,
|
|
841
843
|
computeWalletAuthorizationDigest as computeWalletAuthorizationDigest2,
|
|
842
844
|
walletAuthorizationTypedData as walletAuthorizationTypedData2
|
|
843
845
|
} from "@invisi-labs/core";
|
|
@@ -849,7 +851,7 @@ function selectCreditDrawCircuit(count) {
|
|
|
849
851
|
return {
|
|
850
852
|
name: `credit_draw_slots${maxSize}`,
|
|
851
853
|
maxSize,
|
|
852
|
-
publicInputCount: 6 * maxSize +
|
|
854
|
+
publicInputCount: 6 * maxSize + 14,
|
|
853
855
|
totalBits: 126 + Math.ceil(Math.log2(maxSize))
|
|
854
856
|
};
|
|
855
857
|
}
|
|
@@ -902,7 +904,8 @@ function validateCreditDrawRequest(c, p, cs) {
|
|
|
902
904
|
totalAmount,
|
|
903
905
|
deadline: checkDeadline(c, p.deadline),
|
|
904
906
|
deliveries,
|
|
905
|
-
profile
|
|
907
|
+
profile,
|
|
908
|
+
periods: creditPeriods(c.timestamp)
|
|
906
909
|
};
|
|
907
910
|
}
|
|
908
911
|
function creditDrawBaseInputs(c, p, cs) {
|
|
@@ -929,7 +932,9 @@ function creditDrawBaseInputs(c, p, cs) {
|
|
|
929
932
|
r.deadline,
|
|
930
933
|
h >> 128n,
|
|
931
934
|
h & (1n << 128n) - 1n,
|
|
932
|
-
...pad(r.recoveryAmounts.map(BigInt), n)
|
|
935
|
+
...pad(r.recoveryAmounts.map(BigInt), n),
|
|
936
|
+
r.periods.currentDay,
|
|
937
|
+
r.periods.currentMonth
|
|
933
938
|
].map(word);
|
|
934
939
|
}
|
|
935
940
|
function validateCancelCreditRequest(c, p) {
|
|
@@ -1653,7 +1658,8 @@ async function verifyCreditCommitment(params) {
|
|
|
1653
1658
|
params.amount,
|
|
1654
1659
|
params.nonce,
|
|
1655
1660
|
params.expiry,
|
|
1656
|
-
await computeCreditSharedKeyHash(params.creditSharedKey)
|
|
1661
|
+
await computeCreditSharedKeyHash(params.creditSharedKey),
|
|
1662
|
+
params
|
|
1657
1663
|
);
|
|
1658
1664
|
return BigInt(expected) === BigInt(params.creditCommitment);
|
|
1659
1665
|
}
|
|
@@ -1695,6 +1701,8 @@ async function buildWithdrawalCalldata(p) {
|
|
|
1695
1701
|
// src/witness.ts
|
|
1696
1702
|
import {
|
|
1697
1703
|
computeCreditCommitment as computeCreditCommitment2,
|
|
1704
|
+
normalizeCreditPolicy,
|
|
1705
|
+
applyCreditDrawUsage,
|
|
1698
1706
|
computeCreditNullifier,
|
|
1699
1707
|
computeCreditSharedKeyHash as computeCreditSharedKeyHash2,
|
|
1700
1708
|
computeNoteCommitment as computeNoteCommitment4,
|
|
@@ -2229,9 +2237,9 @@ var witness_layouts_default = {
|
|
|
2229
2237
|
]
|
|
2230
2238
|
},
|
|
2231
2239
|
create_credit: {
|
|
2232
|
-
artifactSha256: "
|
|
2240
|
+
artifactSha256: "3ed6cfdee4f5fd840f023580f76c208768777fea79737f2511377e5c55be0230",
|
|
2233
2241
|
keys: {
|
|
2234
|
-
evm: "
|
|
2242
|
+
evm: "56f663c6053be0d158a271022d200c732597efd3a2e0be48fe94549d0b1795e0"
|
|
2235
2243
|
},
|
|
2236
2244
|
publicInputCount: 46,
|
|
2237
2245
|
public: [
|
|
@@ -2346,16 +2354,19 @@ var witness_layouts_default = {
|
|
|
2346
2354
|
"credit_amount",
|
|
2347
2355
|
"credit_nonce",
|
|
2348
2356
|
"credit_shared_key",
|
|
2357
|
+
"single_limit",
|
|
2358
|
+
"daily_limit",
|
|
2359
|
+
"monthly_limit",
|
|
2349
2360
|
"change_amount",
|
|
2350
2361
|
"change_nonce"
|
|
2351
2362
|
]
|
|
2352
2363
|
},
|
|
2353
2364
|
credit_draw_slots1: {
|
|
2354
|
-
artifactSha256: "
|
|
2365
|
+
artifactSha256: "4542b227e0552b45c302f1dace21cadeba4962c96244e021472f1f7531cff8d1",
|
|
2355
2366
|
keys: {
|
|
2356
|
-
evm: "
|
|
2367
|
+
evm: "43c051a2bedf9454c12e70b10156361e414944823ba23e80662c16c7ced0a2ce"
|
|
2357
2368
|
},
|
|
2358
|
-
publicInputCount:
|
|
2369
|
+
publicInputCount: 20,
|
|
2359
2370
|
public: [
|
|
2360
2371
|
{
|
|
2361
2372
|
name: "chain_id",
|
|
@@ -2437,6 +2448,16 @@ var witness_layouts_default = {
|
|
|
2437
2448
|
count: 1,
|
|
2438
2449
|
array: true
|
|
2439
2450
|
},
|
|
2451
|
+
{
|
|
2452
|
+
name: "current_day",
|
|
2453
|
+
count: 1,
|
|
2454
|
+
array: false
|
|
2455
|
+
},
|
|
2456
|
+
{
|
|
2457
|
+
name: "current_month",
|
|
2458
|
+
count: 1,
|
|
2459
|
+
array: false
|
|
2460
|
+
},
|
|
2440
2461
|
{
|
|
2441
2462
|
name: "auth_digest_high",
|
|
2442
2463
|
count: 1,
|
|
@@ -2461,15 +2482,22 @@ var witness_layouts_default = {
|
|
|
2461
2482
|
"leaf_indices",
|
|
2462
2483
|
"merkle_paths",
|
|
2463
2484
|
"input_source_indices",
|
|
2464
|
-
"draw_amounts"
|
|
2485
|
+
"draw_amounts",
|
|
2486
|
+
"single_limits",
|
|
2487
|
+
"daily_limits",
|
|
2488
|
+
"monthly_limits",
|
|
2489
|
+
"last_days",
|
|
2490
|
+
"daily_spents",
|
|
2491
|
+
"last_months",
|
|
2492
|
+
"monthly_spents"
|
|
2465
2493
|
]
|
|
2466
2494
|
},
|
|
2467
2495
|
credit_draw_slots12: {
|
|
2468
|
-
artifactSha256: "
|
|
2496
|
+
artifactSha256: "dd72b0867fc3be7cd90de263bd2d0892075cb18eb4f6dd671b13111710f10369",
|
|
2469
2497
|
keys: {
|
|
2470
|
-
evm: "
|
|
2498
|
+
evm: "5e31d771e6294993736078596d9c69f21fe7595eda50e3cce6d7406b65cf1443"
|
|
2471
2499
|
},
|
|
2472
|
-
publicInputCount:
|
|
2500
|
+
publicInputCount: 86,
|
|
2473
2501
|
public: [
|
|
2474
2502
|
{
|
|
2475
2503
|
name: "chain_id",
|
|
@@ -2551,6 +2579,16 @@ var witness_layouts_default = {
|
|
|
2551
2579
|
count: 12,
|
|
2552
2580
|
array: true
|
|
2553
2581
|
},
|
|
2582
|
+
{
|
|
2583
|
+
name: "current_day",
|
|
2584
|
+
count: 1,
|
|
2585
|
+
array: false
|
|
2586
|
+
},
|
|
2587
|
+
{
|
|
2588
|
+
name: "current_month",
|
|
2589
|
+
count: 1,
|
|
2590
|
+
array: false
|
|
2591
|
+
},
|
|
2554
2592
|
{
|
|
2555
2593
|
name: "auth_digest_high",
|
|
2556
2594
|
count: 1,
|
|
@@ -2575,15 +2613,22 @@ var witness_layouts_default = {
|
|
|
2575
2613
|
"leaf_indices",
|
|
2576
2614
|
"merkle_paths",
|
|
2577
2615
|
"input_source_indices",
|
|
2578
|
-
"draw_amounts"
|
|
2616
|
+
"draw_amounts",
|
|
2617
|
+
"single_limits",
|
|
2618
|
+
"daily_limits",
|
|
2619
|
+
"monthly_limits",
|
|
2620
|
+
"last_days",
|
|
2621
|
+
"daily_spents",
|
|
2622
|
+
"last_months",
|
|
2623
|
+
"monthly_spents"
|
|
2579
2624
|
]
|
|
2580
2625
|
},
|
|
2581
2626
|
credit_draw_slots50: {
|
|
2582
|
-
artifactSha256: "
|
|
2627
|
+
artifactSha256: "09c7469866748b4c0c4bbf2b040844771948a170999f6dc7a38fe5c0ecda4054",
|
|
2583
2628
|
keys: {
|
|
2584
|
-
evm: "
|
|
2629
|
+
evm: "7b613225b6f32a077011d4196c356e836d22dcd116efe687fde53144fbd8db9f"
|
|
2585
2630
|
},
|
|
2586
|
-
publicInputCount:
|
|
2631
|
+
publicInputCount: 314,
|
|
2587
2632
|
public: [
|
|
2588
2633
|
{
|
|
2589
2634
|
name: "chain_id",
|
|
@@ -2665,6 +2710,16 @@ var witness_layouts_default = {
|
|
|
2665
2710
|
count: 50,
|
|
2666
2711
|
array: true
|
|
2667
2712
|
},
|
|
2713
|
+
{
|
|
2714
|
+
name: "current_day",
|
|
2715
|
+
count: 1,
|
|
2716
|
+
array: false
|
|
2717
|
+
},
|
|
2718
|
+
{
|
|
2719
|
+
name: "current_month",
|
|
2720
|
+
count: 1,
|
|
2721
|
+
array: false
|
|
2722
|
+
},
|
|
2668
2723
|
{
|
|
2669
2724
|
name: "auth_digest_high",
|
|
2670
2725
|
count: 1,
|
|
@@ -2689,15 +2744,22 @@ var witness_layouts_default = {
|
|
|
2689
2744
|
"leaf_indices",
|
|
2690
2745
|
"merkle_paths",
|
|
2691
2746
|
"input_source_indices",
|
|
2692
|
-
"draw_amounts"
|
|
2747
|
+
"draw_amounts",
|
|
2748
|
+
"single_limits",
|
|
2749
|
+
"daily_limits",
|
|
2750
|
+
"monthly_limits",
|
|
2751
|
+
"last_days",
|
|
2752
|
+
"daily_spents",
|
|
2753
|
+
"last_months",
|
|
2754
|
+
"monthly_spents"
|
|
2693
2755
|
]
|
|
2694
2756
|
},
|
|
2695
2757
|
credit_draw_slots120: {
|
|
2696
|
-
artifactSha256: "
|
|
2758
|
+
artifactSha256: "6ccd0366a669c50fd5da875c3eae194fe8aa4c36d35a5f9ebfd64636ea599b48",
|
|
2697
2759
|
keys: {
|
|
2698
|
-
evm: "
|
|
2760
|
+
evm: "d715848afc5c1ecdfcef5ed5026865abef5040a3bc232fd65330a5ffee8475fb"
|
|
2699
2761
|
},
|
|
2700
|
-
publicInputCount:
|
|
2762
|
+
publicInputCount: 734,
|
|
2701
2763
|
public: [
|
|
2702
2764
|
{
|
|
2703
2765
|
name: "chain_id",
|
|
@@ -2779,6 +2841,16 @@ var witness_layouts_default = {
|
|
|
2779
2841
|
count: 120,
|
|
2780
2842
|
array: true
|
|
2781
2843
|
},
|
|
2844
|
+
{
|
|
2845
|
+
name: "current_day",
|
|
2846
|
+
count: 1,
|
|
2847
|
+
array: false
|
|
2848
|
+
},
|
|
2849
|
+
{
|
|
2850
|
+
name: "current_month",
|
|
2851
|
+
count: 1,
|
|
2852
|
+
array: false
|
|
2853
|
+
},
|
|
2782
2854
|
{
|
|
2783
2855
|
name: "auth_digest_high",
|
|
2784
2856
|
count: 1,
|
|
@@ -2803,13 +2875,20 @@ var witness_layouts_default = {
|
|
|
2803
2875
|
"leaf_indices",
|
|
2804
2876
|
"merkle_paths",
|
|
2805
2877
|
"input_source_indices",
|
|
2806
|
-
"draw_amounts"
|
|
2878
|
+
"draw_amounts",
|
|
2879
|
+
"single_limits",
|
|
2880
|
+
"daily_limits",
|
|
2881
|
+
"monthly_limits",
|
|
2882
|
+
"last_days",
|
|
2883
|
+
"daily_spents",
|
|
2884
|
+
"last_months",
|
|
2885
|
+
"monthly_spents"
|
|
2807
2886
|
]
|
|
2808
2887
|
},
|
|
2809
2888
|
credit_cancel: {
|
|
2810
|
-
artifactSha256: "
|
|
2889
|
+
artifactSha256: "b4459c2cf756d096e37291cf4d7cd129866b6d420b6d03c928f383b057112ccb",
|
|
2811
2890
|
keys: {
|
|
2812
|
-
evm: "
|
|
2891
|
+
evm: "fc8ad196ef15f3328afcc8f01d867a3ebefd15451c2813948442fab1923b73b2"
|
|
2813
2892
|
},
|
|
2814
2893
|
publicInputCount: 11,
|
|
2815
2894
|
public: [
|
|
@@ -2879,14 +2958,21 @@ var witness_layouts_default = {
|
|
|
2879
2958
|
"input_nonce",
|
|
2880
2959
|
"expiry",
|
|
2881
2960
|
"credit_shared_key",
|
|
2961
|
+
"single_limit",
|
|
2962
|
+
"daily_limit",
|
|
2963
|
+
"monthly_limit",
|
|
2964
|
+
"last_day",
|
|
2965
|
+
"daily_spent",
|
|
2966
|
+
"last_month",
|
|
2967
|
+
"monthly_spent",
|
|
2882
2968
|
"leaf_index",
|
|
2883
2969
|
"merkle_path"
|
|
2884
2970
|
]
|
|
2885
2971
|
},
|
|
2886
2972
|
credit_top_up: {
|
|
2887
|
-
artifactSha256: "
|
|
2973
|
+
artifactSha256: "2ffebd5753ec1b0c050204d4f97498765fe61ea01a793a9b2466c2f97536345c",
|
|
2888
2974
|
keys: {
|
|
2889
|
-
evm: "
|
|
2975
|
+
evm: "40b02a9d2e7eb7b49daaac4b7760328537b7982fd5a225cc065bb74cd5ef44b3"
|
|
2890
2976
|
},
|
|
2891
2977
|
publicInputCount: 50,
|
|
2892
2978
|
public: [
|
|
@@ -3021,6 +3107,16 @@ var witness_layouts_default = {
|
|
|
3021
3107
|
"credit_amount",
|
|
3022
3108
|
"credit_nonce",
|
|
3023
3109
|
"credit_shared_key",
|
|
3110
|
+
"single_limit",
|
|
3111
|
+
"daily_limit",
|
|
3112
|
+
"monthly_limit",
|
|
3113
|
+
"previous_single_limit",
|
|
3114
|
+
"previous_daily_limit",
|
|
3115
|
+
"previous_monthly_limit",
|
|
3116
|
+
"last_day",
|
|
3117
|
+
"daily_spent",
|
|
3118
|
+
"last_month",
|
|
3119
|
+
"monthly_spent",
|
|
3024
3120
|
"change_amount",
|
|
3025
3121
|
"change_nonce",
|
|
3026
3122
|
"previous_credit_amount",
|
|
@@ -3036,6 +3132,20 @@ var pad2 = (values, count, zero) => {
|
|
|
3036
3132
|
if (values.length > count) throw new Error("witness capacity exceeded");
|
|
3037
3133
|
return [...values, ...Array.from({ length: count - values.length }, zero)];
|
|
3038
3134
|
};
|
|
3135
|
+
var policyWitness = (note, usage = true) => {
|
|
3136
|
+
const p = normalizeCreditPolicy(note);
|
|
3137
|
+
return {
|
|
3138
|
+
single_limit: p.singleLimit,
|
|
3139
|
+
daily_limit: p.dailyLimit,
|
|
3140
|
+
monthly_limit: p.monthlyLimit,
|
|
3141
|
+
...usage ? {
|
|
3142
|
+
last_day: p.lastDay,
|
|
3143
|
+
daily_spent: p.dailySpent,
|
|
3144
|
+
last_month: p.lastMonth,
|
|
3145
|
+
monthly_spent: p.monthlySpent
|
|
3146
|
+
} : {}
|
|
3147
|
+
};
|
|
3148
|
+
};
|
|
3039
3149
|
var zeros = () => Array(16).fill(0n);
|
|
3040
3150
|
var zeroAuthority = () => ({
|
|
3041
3151
|
public_key_x: Array(32).fill(0),
|
|
@@ -3164,7 +3274,8 @@ var WitnessBuilder = class {
|
|
|
3164
3274
|
note.amount,
|
|
3165
3275
|
note.nonce,
|
|
3166
3276
|
note.expiry,
|
|
3167
|
-
await computeCreditSharedKeyHash2(note.creditSharedKey)
|
|
3277
|
+
await computeCreditSharedKeyHash2(note.creditSharedKey),
|
|
3278
|
+
note
|
|
3168
3279
|
);
|
|
3169
3280
|
}
|
|
3170
3281
|
async noteInputs(inputs, sources, nullifiers, identity, authority) {
|
|
@@ -3248,6 +3359,8 @@ var WitnessBuilder = class {
|
|
|
3248
3359
|
await this.creditLeaf(note) === p.params.creditCommitment && note.ownerPayout === BigInt(p.params.owner) && note.expiry === p.params.expiry,
|
|
3249
3360
|
"Credit creation mismatch"
|
|
3250
3361
|
);
|
|
3362
|
+
if (operation === "create-credit" && [note.lastDay, note.dailySpent, note.lastMonth, note.monthlySpent].some((v) => v !== 0n))
|
|
3363
|
+
throw new Error("new Credit usage must be zero");
|
|
3251
3364
|
const authority = await this.authority(
|
|
3252
3365
|
operation,
|
|
3253
3366
|
10,
|
|
@@ -3294,6 +3407,7 @@ var WitnessBuilder = class {
|
|
|
3294
3407
|
spender_payout: note.spenderPayout,
|
|
3295
3408
|
spender_wallet_identity: BigInt(note.spenderWalletIdentity),
|
|
3296
3409
|
owner_wallet_identity: BigInt(note.ownerWalletIdentity),
|
|
3410
|
+
...policyWitness(note, operation === "top-up-credit"),
|
|
3297
3411
|
credit_amount: note.amount,
|
|
3298
3412
|
credit_nonce: note.nonce,
|
|
3299
3413
|
credit_shared_key: note.creditSharedKey,
|
|
@@ -3335,6 +3449,7 @@ var WitnessBuilder = class {
|
|
|
3335
3449
|
spender_payout: note.spenderPayout,
|
|
3336
3450
|
spender_wallet_identity: BigInt(note.spenderWalletIdentity),
|
|
3337
3451
|
owner_wallet_identity: BigInt(note.ownerWalletIdentity),
|
|
3452
|
+
...policyWitness(note),
|
|
3338
3453
|
input_nonce: note.nonce,
|
|
3339
3454
|
expiry: note.expiry,
|
|
3340
3455
|
credit_shared_key: note.creditSharedKey,
|
|
@@ -3345,7 +3460,7 @@ var WitnessBuilder = class {
|
|
|
3345
3460
|
);
|
|
3346
3461
|
}
|
|
3347
3462
|
async drawCredit(p) {
|
|
3348
|
-
const c = this.#protocol.context, profile = selectCreditDrawCircuit(p.inputs.length), capacity = profile.maxSize;
|
|
3463
|
+
const c = { ...this.#protocol.context, timestamp: p.timestamp }, profile = selectCreditDrawCircuit(p.inputs.length), capacity = profile.maxSize;
|
|
3349
3464
|
check2(
|
|
3350
3465
|
p.inputs.length === p.amounts.length && p.inputs.length === p.params.nullifiers.length,
|
|
3351
3466
|
"draw input count mismatch"
|
|
@@ -3360,6 +3475,7 @@ var WitnessBuilder = class {
|
|
|
3360
3475
|
);
|
|
3361
3476
|
const sourceIndices = await Promise.all(
|
|
3362
3477
|
notes2.map(async (note, i) => {
|
|
3478
|
+
applyCreditDrawUsage(note, p.amounts[i], p.timestamp);
|
|
3363
3479
|
const leaf = await this.creditLeaf(note);
|
|
3364
3480
|
check2(
|
|
3365
3481
|
note.spenderWalletIdentity === identity && note.spenderPayout === BigInt(p.params.spender) && note.expiry === p.params.expiries[i] && p.amounts[i] > 0n && p.amounts[i] <= note.amount && await computeCreditNullifier(c.chainId, note.creditSharedKey, leaf) === p.params.nullifiers[i],
|
|
@@ -3372,6 +3488,26 @@ var WitnessBuilder = class {
|
|
|
3372
3488
|
profile.name,
|
|
3373
3489
|
{
|
|
3374
3490
|
...authority,
|
|
3491
|
+
...Object.fromEntries(
|
|
3492
|
+
Object.entries({
|
|
3493
|
+
singleLimit: "single_limits",
|
|
3494
|
+
dailyLimit: "daily_limits",
|
|
3495
|
+
monthlyLimit: "monthly_limits",
|
|
3496
|
+
lastDay: "last_days",
|
|
3497
|
+
dailySpent: "daily_spents",
|
|
3498
|
+
lastMonth: "last_months",
|
|
3499
|
+
monthlySpent: "monthly_spents"
|
|
3500
|
+
}).map(([key, name]) => [
|
|
3501
|
+
name,
|
|
3502
|
+
pad2(
|
|
3503
|
+
notes2.map(
|
|
3504
|
+
(note) => normalizeCreditPolicy(note)[key]
|
|
3505
|
+
),
|
|
3506
|
+
capacity,
|
|
3507
|
+
() => 0n
|
|
3508
|
+
)
|
|
3509
|
+
])
|
|
3510
|
+
),
|
|
3375
3511
|
spender_wallet_identity: BigInt(identity),
|
|
3376
3512
|
owner_payouts: pad2(
|
|
3377
3513
|
notes2.map((note) => note.ownerPayout),
|
|
@@ -3421,7 +3557,11 @@ var WitnessBuilder = class {
|
|
|
3421
3557
|
"ownerWalletIdentity",
|
|
3422
3558
|
"spenderPayout",
|
|
3423
3559
|
"ownerPayout",
|
|
3424
|
-
"creditSharedKey"
|
|
3560
|
+
"creditSharedKey",
|
|
3561
|
+
"lastDay",
|
|
3562
|
+
"dailySpent",
|
|
3563
|
+
"lastMonth",
|
|
3564
|
+
"monthlySpent"
|
|
3425
3565
|
])
|
|
3426
3566
|
check2(old[field2] === note[field2], "Credit role or payout changed");
|
|
3427
3567
|
check2(
|
|
@@ -3442,6 +3582,9 @@ var WitnessBuilder = class {
|
|
|
3442
3582
|
"credit_top_up",
|
|
3443
3583
|
{
|
|
3444
3584
|
...base,
|
|
3585
|
+
previous_single_limit: old.singleLimit,
|
|
3586
|
+
previous_daily_limit: old.dailyLimit,
|
|
3587
|
+
previous_monthly_limit: old.monthlyLimit,
|
|
3445
3588
|
previous_credit_amount: old.amount,
|
|
3446
3589
|
previous_credit_nonce: old.nonce,
|
|
3447
3590
|
previous_credit_leaf_index: BigInt(p.previous.leafIndex),
|