@invisi-labs/protocol 1.1.7 → 1.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -0
- package/dist/chunk-7SS2YSEF.js +199 -0
- package/dist/chunk-7SS2YSEF.js.map +1 -0
- package/dist/{chunk-BYJ4LXCJ.js → chunk-HHJLFLVJ.js} +616 -714
- package/dist/chunk-HHJLFLVJ.js.map +1 -0
- package/dist/chunk-MVQQD5W5.js +487 -0
- package/dist/chunk-MVQQD5W5.js.map +1 -0
- package/dist/chunk-Z2XPYNMC.js +446 -0
- package/dist/chunk-Z2XPYNMC.js.map +1 -0
- package/dist/contracts.cjs +615 -713
- package/dist/contracts.cjs.map +1 -1
- package/dist/contracts.d.cts +5 -5
- package/dist/contracts.d.ts +5 -5
- package/dist/contracts.js +1 -1
- package/dist/credit.cjs +3367 -0
- package/dist/credit.cjs.map +1 -0
- package/dist/credit.d.cts +252 -0
- package/dist/credit.d.ts +252 -0
- package/dist/credit.js +53 -0
- package/dist/credit.js.map +1 -0
- package/dist/index.cjs +6054 -6053
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +89 -893
- package/dist/index.d.ts +89 -893
- package/dist/index.js +2956 -3762
- package/dist/index.js.map +1 -1
- package/dist/note.cjs +3456 -0
- package/dist/note.cjs.map +1 -0
- package/dist/note.d.cts +232 -0
- package/dist/note.d.ts +232 -0
- package/dist/note.js +43 -0
- package/dist/note.js.map +1 -0
- package/dist/provenance.cjs +558 -0
- package/dist/provenance.cjs.map +1 -0
- package/dist/provenance.d.cts +188 -0
- package/dist/provenance.d.ts +188 -0
- package/dist/provenance.js +499 -0
- package/dist/provenance.js.map +1 -0
- package/dist/{types-Bvakbfeb.d.cts → types-CUnFzl5S.d.cts} +530 -590
- package/dist/{types-Bvakbfeb.d.ts → types-CUnFzl5S.d.ts} +530 -590
- package/dist/validation-8g0SQVE5.d.ts +235 -0
- package/dist/validation-MgURYiNF.d.cts +235 -0
- package/package.json +20 -5
- package/dist/chunk-BYJ4LXCJ.js.map +0 -1
package/README.md
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
# @invisi-labs/protocol
|
|
2
|
+
|
|
3
|
+
Pure public protocol contracts: ABIs, public DTOs, strict codecs, public inputs, signature digests, capacities, deployment validation and documented gas references. Depends on primitives; contains no network calls or proving runtime.
|
|
4
|
+
|
|
5
|
+
Install with `npm install @invisi-labs/protocol@1.2.0`. API documentation and runnable examples are in the [SDK repository](https://github.com/invisi-lab/invisi-sdk-ts).
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
// src/validation.ts
|
|
2
|
+
import { MAX_CIPHERTEXT_BYTES } from "@invisi-labs/primitives";
|
|
3
|
+
import {
|
|
4
|
+
AbiCoder,
|
|
5
|
+
dataLength,
|
|
6
|
+
getAddress,
|
|
7
|
+
isHexString,
|
|
8
|
+
keccak256,
|
|
9
|
+
ParamType,
|
|
10
|
+
toBeHex
|
|
11
|
+
} from "ethers";
|
|
12
|
+
var FIELD_MODULUS = 21888242871839275222246405745257275088548364400416034343698204186575808495617n;
|
|
13
|
+
var ZERO_ADDRESS = "0x0000000000000000000000000000000000000000";
|
|
14
|
+
var ZERO_WORD = toBeHex(0n, 32);
|
|
15
|
+
var EMPTY_PERMIT = {
|
|
16
|
+
deadline: 0n,
|
|
17
|
+
v: 0,
|
|
18
|
+
r: ZERO_WORD,
|
|
19
|
+
s: ZERO_WORD
|
|
20
|
+
};
|
|
21
|
+
var EMPTY_FUNDING = {
|
|
22
|
+
payer: ZERO_ADDRESS,
|
|
23
|
+
amount: 0n,
|
|
24
|
+
sigNonce: 0n,
|
|
25
|
+
deadline: 0n,
|
|
26
|
+
signature: "0x",
|
|
27
|
+
permit: EMPTY_PERMIT
|
|
28
|
+
};
|
|
29
|
+
function uint(v, bits, name = "value") {
|
|
30
|
+
if (typeof v !== "bigint" && typeof v !== "number" && typeof v !== "string" || typeof v === "number" && !Number.isSafeInteger(v))
|
|
31
|
+
throw new Error(`${name} must be an integer`);
|
|
32
|
+
const n = BigInt(v);
|
|
33
|
+
if (n < 0n || n >= 1n << BigInt(bits)) throw new Error(`${name} exceeds u${bits}`);
|
|
34
|
+
return n;
|
|
35
|
+
}
|
|
36
|
+
function field(v, name = "field") {
|
|
37
|
+
const n = uint(v, 256, name);
|
|
38
|
+
if (n >= FIELD_MODULUS) throw new Error(`${name} is noncanonical field`);
|
|
39
|
+
return n;
|
|
40
|
+
}
|
|
41
|
+
var word = (v) => toBeHex(typeof v === "bigint" ? v : BigInt(v), 32);
|
|
42
|
+
function dense(v, name) {
|
|
43
|
+
if (!Array.isArray(v)) throw new Error(`${name} must be array`);
|
|
44
|
+
for (let i = 0; i < v.length; i++)
|
|
45
|
+
if (!Object.hasOwn(v, i) || v[i] === void 0 || v[i] === null)
|
|
46
|
+
throw new Error(`${name} has missing or sparse entries`);
|
|
47
|
+
return v;
|
|
48
|
+
}
|
|
49
|
+
function known(v, keys, name = "params") {
|
|
50
|
+
if (!v || typeof v !== "object" || Array.isArray(v) || Object.keys(v).some((k) => !keys.includes(k)))
|
|
51
|
+
throw new Error(`${name} has unsupported fields`);
|
|
52
|
+
}
|
|
53
|
+
function notes(v, name) {
|
|
54
|
+
const r = dense(v, name).map((v2) => word(field(v2, name)));
|
|
55
|
+
if (r.some((v2) => BigInt(v2) === 0n) || new Set(r).size !== r.length)
|
|
56
|
+
throw new Error(`duplicate or zero ${name}`);
|
|
57
|
+
return r;
|
|
58
|
+
}
|
|
59
|
+
function envelope(v, length, version, maximum = length) {
|
|
60
|
+
if (!isHexString(v) || !/^0x(?:[a-fA-F0-9]{2})*$/.test(v) || dataLength(v) < length || dataLength(v) > maximum)
|
|
61
|
+
throw new Error(`ciphertext must be ${length} bytes`);
|
|
62
|
+
if (version !== void 0 && Number.parseInt(v.slice(2, 4), 16) !== version)
|
|
63
|
+
throw new Error("unsupported ciphertext envelope version");
|
|
64
|
+
return v;
|
|
65
|
+
}
|
|
66
|
+
function normalizeContext(c) {
|
|
67
|
+
return {
|
|
68
|
+
...c,
|
|
69
|
+
chainId: uint(c.chainId, 64, "chainId"),
|
|
70
|
+
protocolAddress: getAddress(c.protocolAddress),
|
|
71
|
+
tokenAddress: getAddress(c.tokenAddress)
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
function checkDeadline(c, value) {
|
|
75
|
+
const n = uint(value, 64, "deadline");
|
|
76
|
+
if (c.now !== void 0 && n < uint(c.now, 64, "now")) throw new Error("deadline has expired");
|
|
77
|
+
return n;
|
|
78
|
+
}
|
|
79
|
+
function normalizeSources(sources, inputCount, capacity) {
|
|
80
|
+
dense(sources, "sources");
|
|
81
|
+
if (inputCount < 0 || inputCount > capacity || sources.length > inputCount || (inputCount === 0 ? sources.length !== 0 : sources.length === 0))
|
|
82
|
+
throw new Error("source count must be 1..inputCount, or empty for zero inputs");
|
|
83
|
+
let previous = 0n;
|
|
84
|
+
return sources.map((s) => {
|
|
85
|
+
known(s, ["treeId", "merkleRoot"], "source");
|
|
86
|
+
const treeId = uint(s.treeId, 64, "treeId"), merkleRoot = word(field(s.merkleRoot, "merkleRoot"));
|
|
87
|
+
if (treeId === 0n || treeId <= previous || BigInt(merkleRoot) === 0n)
|
|
88
|
+
throw new Error("sources must have positive roots and strictly ascending tree IDs");
|
|
89
|
+
previous = treeId;
|
|
90
|
+
return { treeId, merkleRoot };
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
var pad = (v, n) => [
|
|
94
|
+
...v,
|
|
95
|
+
...Array(n - v.length).fill(0n)
|
|
96
|
+
];
|
|
97
|
+
function normalizeOpaqueDelivery(value, options = {}) {
|
|
98
|
+
known(value, ["ciphertext", "clue"], "delivery");
|
|
99
|
+
if (options.empty) {
|
|
100
|
+
if (value.ciphertext !== "0x" || value.clue !== "0x")
|
|
101
|
+
throw new Error("absent output requires an empty delivery");
|
|
102
|
+
return { ciphertext: "0x", clue: "0x" };
|
|
103
|
+
}
|
|
104
|
+
if (options.allowEmpty && value.ciphertext === "0x" && value.clue === "0x")
|
|
105
|
+
return { ciphertext: "0x", clue: "0x" };
|
|
106
|
+
const ciphertext = envelope(value.ciphertext, 1, void 0, MAX_CIPHERTEXT_BYTES);
|
|
107
|
+
const clue = envelope(value.clue, 68);
|
|
108
|
+
if (clue.slice(130, 132).toLowerCase() !== "18") throw new Error("clue precision must be 24");
|
|
109
|
+
return { ciphertext, clue };
|
|
110
|
+
}
|
|
111
|
+
var deliveriesHash = (v) => keccak256(
|
|
112
|
+
AbiCoder.defaultAbiCoder().encode(
|
|
113
|
+
[
|
|
114
|
+
{
|
|
115
|
+
type: "tuple[]",
|
|
116
|
+
components: [
|
|
117
|
+
{ name: "ciphertext", type: "bytes" },
|
|
118
|
+
{ name: "clue", type: "bytes" }
|
|
119
|
+
]
|
|
120
|
+
}
|
|
121
|
+
].map((parameter) => ParamType.from(parameter)),
|
|
122
|
+
[dense(v, "deliveries")]
|
|
123
|
+
)
|
|
124
|
+
);
|
|
125
|
+
function normalizeFunding(input = {}) {
|
|
126
|
+
const f = { ...EMPTY_FUNDING, ...input };
|
|
127
|
+
getAddress(f.payer);
|
|
128
|
+
uint(f.amount, 128, "depositAmount");
|
|
129
|
+
uint(f.sigNonce, 256, "sigNonce");
|
|
130
|
+
uint(f.deadline, 256, "funding deadline");
|
|
131
|
+
if (!isHexString(f.signature) || !/^0x(?:[a-fA-F0-9]{2})*$/.test(f.signature))
|
|
132
|
+
throw new Error("invalid signature bytes");
|
|
133
|
+
const p = f.permit;
|
|
134
|
+
uint(p.deadline, 256);
|
|
135
|
+
uint(p.v, 8);
|
|
136
|
+
for (const v of [p.r, p.s])
|
|
137
|
+
if (!isHexString(v) || dataLength(v) !== 32) throw new Error("permit r/s must be bytes32");
|
|
138
|
+
if (f.amount === 0n !== (BigInt(f.payer) === 0n))
|
|
139
|
+
throw new Error("deposit amount and payer must both be zero or positive");
|
|
140
|
+
if (f.amount === 0n && (f.sigNonce !== 0n || f.deadline !== 0n || f.signature !== "0x" || p.deadline !== 0n || p.v !== 0 || BigInt(p.r) !== 0n || BigInt(p.s) !== 0n))
|
|
141
|
+
throw new Error("zero funding must be entirely empty");
|
|
142
|
+
return { ...f, payer: getAddress(f.payer) };
|
|
143
|
+
}
|
|
144
|
+
function validateFundingSubmission(f, caller, now) {
|
|
145
|
+
if (f.signature !== "0x" && now !== void 0 && uint(now, 64, "now") > f.deadline)
|
|
146
|
+
throw new Error("funding authorization has expired");
|
|
147
|
+
if (f.signature === "0x" && (f.sigNonce !== 0n || f.deadline !== 0n || caller !== void 0 && f.amount > 0n && getAddress(caller) !== f.payer))
|
|
148
|
+
throw new Error("direct funding requires payer caller and zero nonce/deadline");
|
|
149
|
+
}
|
|
150
|
+
var getEIP712Domain = (c) => ({
|
|
151
|
+
name: "InvisibleProtocol",
|
|
152
|
+
version: "1",
|
|
153
|
+
chainId: uint(c.chainId, 64),
|
|
154
|
+
verifyingContract: getAddress(c.protocolAddress)
|
|
155
|
+
});
|
|
156
|
+
var fundingFields = [
|
|
157
|
+
{ name: "requestHash", type: "bytes32" },
|
|
158
|
+
{ name: "payer", type: "address" },
|
|
159
|
+
{ name: "amount", type: "uint256" },
|
|
160
|
+
{ name: "sigNonce", type: "uint256" },
|
|
161
|
+
{ name: "deadline", type: "uint256" }
|
|
162
|
+
];
|
|
163
|
+
|
|
164
|
+
// src/fees/fee.ts
|
|
165
|
+
import { getAddress as getAddress2 } from "ethers";
|
|
166
|
+
function normalizeFee(p) {
|
|
167
|
+
const feeRecipient = getAddress2(p.feeRecipient ?? ZERO_ADDRESS);
|
|
168
|
+
const feeAmount = uint(p.feeAmount ?? 0n, 128, "feeAmount");
|
|
169
|
+
if (BigInt(feeRecipient) === 0n !== (feeAmount === 0n))
|
|
170
|
+
throw new Error("invalid fee context");
|
|
171
|
+
return { feeRecipient, feeAmount };
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
export {
|
|
175
|
+
FIELD_MODULUS,
|
|
176
|
+
ZERO_ADDRESS,
|
|
177
|
+
ZERO_WORD,
|
|
178
|
+
EMPTY_PERMIT,
|
|
179
|
+
EMPTY_FUNDING,
|
|
180
|
+
uint,
|
|
181
|
+
field,
|
|
182
|
+
word,
|
|
183
|
+
dense,
|
|
184
|
+
known,
|
|
185
|
+
notes,
|
|
186
|
+
envelope,
|
|
187
|
+
normalizeContext,
|
|
188
|
+
checkDeadline,
|
|
189
|
+
normalizeSources,
|
|
190
|
+
pad,
|
|
191
|
+
normalizeOpaqueDelivery,
|
|
192
|
+
deliveriesHash,
|
|
193
|
+
normalizeFunding,
|
|
194
|
+
validateFundingSubmission,
|
|
195
|
+
getEIP712Domain,
|
|
196
|
+
fundingFields,
|
|
197
|
+
normalizeFee
|
|
198
|
+
};
|
|
199
|
+
//# sourceMappingURL=chunk-7SS2YSEF.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/validation.ts","../src/fees/fee.ts"],"sourcesContent":["import { MAX_CIPHERTEXT_BYTES } from \"@invisi-labs/primitives\";\nimport type { DeploymentContext } from \"./rpc-types\";\nimport {\n AbiCoder,\n dataLength,\n getAddress,\n isHexString,\n keccak256,\n ParamType,\n toBeHex,\n} from \"ethers\";\nimport type { Address, Delivery, FundingParams, Hex, InputSource } from \"./contracts/index\";\n\nexport type { DeploymentContext } from \"./rpc-types\";\nexport interface TransactionContext extends DeploymentContext {\n tokenAddress: Address;\n now?: bigint;\n /** Explicit chain timestamp used to bind Credit draw UTC periods. */\n timestamp?: bigint;\n}\nexport const FIELD_MODULUS =\n 21888242871839275222246405745257275088548364400416034343698204186575808495617n;\nexport const ZERO_ADDRESS = \"0x0000000000000000000000000000000000000000\" as const;\nexport const ZERO_WORD = toBeHex(0n, 32) as Hex;\nexport const EMPTY_PERMIT = {\n deadline: 0n,\n v: 0,\n r: ZERO_WORD,\n s: ZERO_WORD,\n} as const;\nexport const EMPTY_FUNDING: FundingParams = {\n payer: ZERO_ADDRESS,\n amount: 0n,\n sigNonce: 0n,\n deadline: 0n,\n signature: \"0x\",\n permit: EMPTY_PERMIT,\n};\nexport type FundingInput = Partial<Omit<FundingParams, \"permit\">> & {\n permit?: FundingParams[\"permit\"];\n};\nexport function uint(v: bigint | number | string, bits: number, name = \"value\"): bigint {\n if (\n (typeof v !== \"bigint\" && typeof v !== \"number\" && typeof v !== \"string\") ||\n (typeof v === \"number\" && !Number.isSafeInteger(v))\n )\n throw new Error(`${name} must be an integer`);\n const n = BigInt(v);\n if (n < 0n || n >= 1n << BigInt(bits)) throw new Error(`${name} exceeds u${bits}`);\n return n;\n}\nexport function field(v: bigint | string, name = \"field\"): bigint {\n const n = uint(v, 256, name);\n if (n >= FIELD_MODULUS) throw new Error(`${name} is noncanonical field`);\n return n;\n}\nexport const word = (v: bigint | string): Hex =>\n toBeHex(typeof v === \"bigint\" ? v : BigInt(v), 32) as Hex;\nexport function dense<T>(v: readonly T[], name: string): readonly T[] {\n if (!Array.isArray(v)) throw new Error(`${name} must be array`);\n for (let i = 0; i < v.length; i++)\n if (!Object.hasOwn(v, i) || v[i] === undefined || v[i] === null)\n throw new Error(`${name} has missing or sparse entries`);\n return v;\n}\nexport function known(v: object, keys: readonly string[], name = \"params\") {\n if (\n !v ||\n typeof v !== \"object\" ||\n Array.isArray(v) ||\n Object.keys(v).some((k) => !keys.includes(k))\n )\n throw new Error(`${name} has unsupported fields`);\n}\nexport function notes(v: readonly Hex[], name: string) {\n const r = dense(v, name).map((v) => word(field(v, name)));\n if (r.some((v) => BigInt(v) === 0n) || new Set(r).size !== r.length)\n throw new Error(`duplicate or zero ${name}`);\n return r;\n}\nexport function envelope(v: Hex, length: number, version?: number, maximum = length): Hex {\n if (\n !isHexString(v) ||\n !/^0x(?:[a-fA-F0-9]{2})*$/.test(v) ||\n dataLength(v) < length ||\n dataLength(v) > maximum\n )\n throw new Error(`ciphertext must be ${length} bytes`);\n if (version !== undefined && Number.parseInt(v.slice(2, 4), 16) !== version)\n throw new Error(\"unsupported ciphertext envelope version\");\n return v;\n}\nexport function normalizeContext(c: TransactionContext) {\n return {\n ...c,\n chainId: uint(c.chainId, 64, \"chainId\"),\n protocolAddress: getAddress(c.protocolAddress) as Hex,\n tokenAddress: getAddress(c.tokenAddress) as Hex,\n };\n}\nexport function checkDeadline(c: TransactionContext, value: bigint) {\n const n = uint(value, 64, \"deadline\");\n if (c.now !== undefined && n < uint(c.now, 64, \"now\")) throw new Error(\"deadline has expired\");\n return n;\n}\nexport function normalizeSources(\n sources: readonly InputSource[],\n inputCount: number,\n capacity: number\n) {\n dense(sources, \"sources\");\n if (\n inputCount < 0 ||\n inputCount > capacity ||\n sources.length > inputCount ||\n (inputCount === 0 ? sources.length !== 0 : sources.length === 0)\n )\n throw new Error(\"source count must be 1..inputCount, or empty for zero inputs\");\n let previous = 0n;\n return sources.map((s) => {\n known(s, [\"treeId\", \"merkleRoot\"], \"source\");\n const treeId = uint(s.treeId, 64, \"treeId\"),\n merkleRoot = word(field(s.merkleRoot, \"merkleRoot\"));\n if (treeId === 0n || treeId <= previous || BigInt(merkleRoot) === 0n)\n throw new Error(\"sources must have positive roots and strictly ascending tree IDs\");\n previous = treeId;\n return { treeId, merkleRoot };\n });\n}\nexport const pad = (v: readonly bigint[], n: number): bigint[] => [\n ...v,\n ...(Array(n - v.length).fill(0n) as bigint[]),\n];\n/** Receipt/transport validation must not reject unrelated future wallet codecs. */\nexport function normalizeOpaqueDelivery(\n value: Delivery,\n options: { empty?: boolean; allowEmpty?: boolean } = {}\n): Delivery {\n known(value, [\"ciphertext\", \"clue\"], \"delivery\");\n if (options.empty) {\n if (value.ciphertext !== \"0x\" || value.clue !== \"0x\")\n throw new Error(\"absent output requires an empty delivery\");\n return { ciphertext: \"0x\", clue: \"0x\" };\n }\n if (options.allowEmpty && value.ciphertext === \"0x\" && value.clue === \"0x\")\n return { ciphertext: \"0x\", clue: \"0x\" };\n const ciphertext = envelope(value.ciphertext, 1, undefined, MAX_CIPHERTEXT_BYTES);\n const clue = envelope(value.clue, 68);\n if (clue.slice(130, 132).toLowerCase() !== \"18\") throw new Error(\"clue precision must be 24\");\n return { ciphertext, clue };\n}\n\nexport const deliveriesHash = (v: readonly Delivery[]) =>\n keccak256(\n AbiCoder.defaultAbiCoder().encode(\n [\n {\n type: \"tuple[]\",\n components: [\n { name: \"ciphertext\", type: \"bytes\" },\n { name: \"clue\", type: \"bytes\" },\n ],\n },\n ].map((parameter) => ParamType.from(parameter)),\n [dense(v, \"deliveries\")]\n ) as Hex\n ) as Hex;\nexport function normalizeFunding(input: FundingInput = {}): FundingParams {\n const f = { ...EMPTY_FUNDING, ...input };\n getAddress(f.payer) as Hex;\n uint(f.amount, 128, \"depositAmount\");\n uint(f.sigNonce, 256, \"sigNonce\");\n uint(f.deadline, 256, \"funding deadline\");\n if (!isHexString(f.signature) || !/^0x(?:[a-fA-F0-9]{2})*$/.test(f.signature))\n throw new Error(\"invalid signature bytes\");\n const p = f.permit;\n uint(p.deadline, 256);\n uint(p.v, 8);\n for (const v of [p.r, p.s])\n if (!isHexString(v) || dataLength(v) !== 32) throw new Error(\"permit r/s must be bytes32\");\n if ((f.amount === 0n) !== (BigInt(f.payer) === 0n))\n throw new Error(\"deposit amount and payer must both be zero or positive\");\n if (\n f.amount === 0n &&\n (f.sigNonce !== 0n ||\n f.deadline !== 0n ||\n f.signature !== \"0x\" ||\n p.deadline !== 0n ||\n p.v !== 0 ||\n BigInt(p.r) !== 0n ||\n BigInt(p.s) !== 0n)\n )\n throw new Error(\"zero funding must be entirely empty\");\n return { ...f, payer: getAddress(f.payer) as Hex };\n}\nexport function validateFundingSubmission(f: FundingParams, caller?: Address, now?: bigint) {\n if (f.signature !== \"0x\" && now !== undefined && uint(now, 64, \"now\") > f.deadline)\n throw new Error(\"funding authorization has expired\");\n if (\n f.signature === \"0x\" &&\n (f.sigNonce !== 0n ||\n f.deadline !== 0n ||\n (caller !== undefined && f.amount > 0n && (getAddress(caller) as Hex) !== f.payer))\n )\n throw new Error(\"direct funding requires payer caller and zero nonce/deadline\");\n}\nexport const getEIP712Domain = (c: TransactionContext) => ({\n name: \"InvisibleProtocol\",\n version: \"1\",\n chainId: uint(c.chainId, 64),\n verifyingContract: getAddress(c.protocolAddress) as Hex,\n});\nexport const fundingFields = [\n { name: \"requestHash\", type: \"bytes32\" },\n { name: \"payer\", type: \"address\" },\n { name: \"amount\", type: \"uint256\" },\n { name: \"sigNonce\", type: \"uint256\" },\n { name: \"deadline\", type: \"uint256\" },\n] as const;\n","import { getAddress } from \"ethers\";\nimport type { Address } from \"../contracts/index\";\nimport { uint, ZERO_ADDRESS } from \"../validation\";\n/** Canonical optional public fee. Omitting both fields explicitly selects zero fee. */\nexport function normalizeFee(p: { feeRecipient?: Address; feeAmount?: bigint }) {\n const feeRecipient = getAddress(p.feeRecipient ?? ZERO_ADDRESS) as Address;\n const feeAmount = uint(p.feeAmount ?? 0n, 128, \"feeAmount\");\n if ((BigInt(feeRecipient) === 0n) !== (feeAmount === 0n))\n throw new Error(\"invalid fee context\");\n return { feeRecipient, feeAmount };\n}\n"],"mappings":";AAAA,SAAS,4BAA4B;AAErC;AAAA,EACI;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACG;AAUA,IAAM,gBACT;AACG,IAAM,eAAe;AACrB,IAAM,YAAY,QAAQ,IAAI,EAAE;AAChC,IAAM,eAAe;AAAA,EACxB,UAAU;AAAA,EACV,GAAG;AAAA,EACH,GAAG;AAAA,EACH,GAAG;AACP;AACO,IAAM,gBAA+B;AAAA,EACxC,OAAO;AAAA,EACP,QAAQ;AAAA,EACR,UAAU;AAAA,EACV,UAAU;AAAA,EACV,WAAW;AAAA,EACX,QAAQ;AACZ;AAIO,SAAS,KAAK,GAA6B,MAAc,OAAO,SAAiB;AACpF,MACK,OAAO,MAAM,YAAY,OAAO,MAAM,YAAY,OAAO,MAAM,YAC/D,OAAO,MAAM,YAAY,CAAC,OAAO,cAAc,CAAC;AAEjD,UAAM,IAAI,MAAM,GAAG,IAA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