@ocap/mcrypto 1.31.8 → 1.32.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/esm/bridge-governance/evm-abi.d.mts +179 -0
- package/esm/bridge-governance/evm-abi.mjs +344 -0
- package/esm/bridge-governance/evm-proposals.d.mts +39 -0
- package/esm/bridge-governance/evm-proposals.mjs +345 -0
- package/esm/bridge-governance/evm-sync.d.mts +45 -0
- package/esm/bridge-governance/evm-sync.mjs +120 -0
- package/esm/bridge-governance/index.d.mts +8 -0
- package/esm/bridge-governance/index.mjs +9 -0
- package/esm/bridge-governance/keys.d.mts +60 -0
- package/esm/bridge-governance/keys.mjs +224 -0
- package/esm/bridge-governance/membership.d.mts +116 -0
- package/esm/bridge-governance/membership.mjs +175 -0
- package/esm/bridge-governance/ocap-proposals.d.mts +132 -0
- package/esm/bridge-governance/ocap-proposals.mjs +481 -0
- package/esm/bridge-governance/strict-json.d.mts +8 -0
- package/esm/bridge-governance/strict-json.mjs +102 -0
- package/esm/bridge-governance.d.mts +9 -116
- package/esm/bridge-governance.mjs +8 -174
- package/esm/envelope.mjs +28 -1
- package/esm/index.d.mts +10 -2
- package/esm/index.mjs +8 -2
- package/esm/signer/ethereum.mjs +2 -2
- package/esm/signer/secp256k1.d.mts +5 -0
- package/esm/signer/secp256k1.mjs +18 -0
- package/lib/_vendor/@noble/hashes/utils.cjs +19 -1
- package/lib/bridge-governance/evm-abi.cjs +362 -0
- package/lib/bridge-governance/evm-abi.d.cts +179 -0
- package/lib/bridge-governance/evm-proposals.cjs +353 -0
- package/lib/bridge-governance/evm-proposals.d.cts +39 -0
- package/lib/bridge-governance/evm-sync.cjs +130 -0
- package/lib/bridge-governance/evm-sync.d.cts +45 -0
- package/lib/bridge-governance/index.cjs +129 -0
- package/lib/bridge-governance/index.d.cts +8 -0
- package/lib/bridge-governance/keys.cjs +273 -0
- package/lib/bridge-governance/keys.d.cts +60 -0
- package/lib/bridge-governance/membership.cjs +195 -0
- package/lib/bridge-governance/membership.d.cts +116 -0
- package/lib/bridge-governance/ocap-proposals.cjs +491 -0
- package/lib/bridge-governance/ocap-proposals.d.cts +132 -0
- package/lib/bridge-governance/strict-json.cjs +103 -0
- package/lib/bridge-governance/strict-json.d.cts +8 -0
- package/lib/bridge-governance.cjs +128 -194
- package/lib/bridge-governance.d.cts +8 -116
- package/lib/envelope.cjs +28 -1
- package/lib/index.cjs +128 -21
- package/lib/index.d.cts +9 -2
- package/lib/signer/secp256k1.cjs +18 -0
- package/lib/signer/secp256k1.d.cts +5 -0
- package/package.json +2 -2
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
import { secp256k1 } from "@noble/curves/secp256k1.js";
|
|
2
|
+
import { keccak_256 } from "@noble/hashes/sha3.js";
|
|
3
|
+
import { bytesToHex, concatBytes, hexToBytes, utf8ToBytes } from "@noble/hashes/utils.js";
|
|
4
|
+
|
|
5
|
+
//#region src/bridge-governance/keys.ts
|
|
6
|
+
const BRIDGE_GOV_INDEX_TAG = "gi:";
|
|
7
|
+
const BRIDGE_GOV_DOC_TAG = "gd:";
|
|
8
|
+
/** Matches every canonical 66-char bridge governance evidence key (`gi:` or `gd:` + 63 lowercase hex chars). */
|
|
9
|
+
const BRIDGE_GOV_KEY_PATTERN = /^g[id]:[0-9a-f]{63}$/;
|
|
10
|
+
const EVM_PROPOSAL_HASH_PREFIX = "ArcBridgeGovProposalV1\n";
|
|
11
|
+
const OCAP_PROPOSAL_HASH_PREFIX = "ArcBridgeOcapGovProposalV1\n";
|
|
12
|
+
const EVM_GOV_CONFIG_HASH_PREFIX = "ArcBridgeEvmGovConfigV1\n";
|
|
13
|
+
const MAX_PROPOSAL_TITLE_CHARS = 160;
|
|
14
|
+
const MAX_PROPOSAL_SUMMARY_BYTES = 500;
|
|
15
|
+
const MAX_PROPOSAL_RATIONALE_URL_BYTES = 512;
|
|
16
|
+
const MAX_PROPOSAL_JSON_BYTES = 16 * 1024;
|
|
17
|
+
const MAX_GOV_DOC_JSON_BYTES = 32 * 1024;
|
|
18
|
+
const MAX_EVM_GOV_ROSTER_JSON_BYTES = 2 * 1024;
|
|
19
|
+
const MAX_EVM_SIGNERS = 32;
|
|
20
|
+
const MAX_OCAP_VALIDATORS = 16;
|
|
21
|
+
const MIN_OCAP_VALIDATORS = 3;
|
|
22
|
+
const MAX_OCAP_PAUSERS = 3;
|
|
23
|
+
const MAX_OCAP_DELAY_SEC = 2160 * 3600;
|
|
24
|
+
const ZERO_ADDRESS = "0x0000000000000000000000000000000000000000";
|
|
25
|
+
const ZERO_BYTES32 = `0x${"0".repeat(64)}`;
|
|
26
|
+
const MAX_U64 = (1n << 64n) - 1n;
|
|
27
|
+
const MAX_U256 = (1n << 256n) - 1n;
|
|
28
|
+
const MAX_SAFE_BIGINT = BigInt(Number.MAX_SAFE_INTEGER);
|
|
29
|
+
const BARE_BASE58_DID_RE = /^z[1-9A-HJ-NP-Za-km-z]{20,60}$/;
|
|
30
|
+
const SAFE_CHAIN_ID_RE = /^[A-Za-z0-9._:-]{1,64}$/;
|
|
31
|
+
const FORBIDDEN_PLAIN_TEXT_RE = /[<>]|[\u0000-\u0008\u000B\u000C\u000E-\u001F\u007F-\u009F\u202A-\u202E\u2066-\u2069]/;
|
|
32
|
+
const FORBIDDEN_SINGLE_LINE_RE = /[\r\n]/;
|
|
33
|
+
function utf8ByteLength(s) {
|
|
34
|
+
return utf8ToBytes(s).byteLength;
|
|
35
|
+
}
|
|
36
|
+
function assertWellFormedString(val, name) {
|
|
37
|
+
if (typeof val !== "string") throw new Error(`${name} must be a string`);
|
|
38
|
+
for (let i = 0; i < val.length; i++) {
|
|
39
|
+
const code = val.charCodeAt(i);
|
|
40
|
+
if (code >= 55296 && code <= 56319) {
|
|
41
|
+
const next = i + 1 < val.length ? val.charCodeAt(i + 1) : 0;
|
|
42
|
+
if (next < 56320 || next > 57343) throw new Error(`${name} contains an unpaired UTF-16 surrogate`);
|
|
43
|
+
i++;
|
|
44
|
+
} else if (code >= 56320 && code <= 57343) throw new Error(`${name} contains an unpaired UTF-16 surrogate`);
|
|
45
|
+
}
|
|
46
|
+
return val;
|
|
47
|
+
}
|
|
48
|
+
function assertPlainObject(val, name) {
|
|
49
|
+
if (val === null || typeof val !== "object" || Array.isArray(val)) throw new Error(`${name} must be a plain JSON object`);
|
|
50
|
+
const proto = Object.getPrototypeOf(val);
|
|
51
|
+
if (proto !== Object.prototype && proto !== null) throw new Error(`${name} must be a plain JSON object`);
|
|
52
|
+
return val;
|
|
53
|
+
}
|
|
54
|
+
function assertAllowedKeys(obj, allowed, name) {
|
|
55
|
+
for (const key of Object.keys(obj)) if (!allowed.has(key)) throw new Error(`unexpected key "${key}" in ${name}`);
|
|
56
|
+
}
|
|
57
|
+
function assertTrimmedSingleLine(val, name, maxBytes, forbidSpace = false) {
|
|
58
|
+
const s = assertWellFormedString(val, name);
|
|
59
|
+
if (s.length === 0 || s !== s.trim()) throw new Error(`${name} must be non-empty without leading or trailing whitespace`);
|
|
60
|
+
if (FORBIDDEN_PLAIN_TEXT_RE.test(s) || FORBIDDEN_SINGLE_LINE_RE.test(s)) throw new Error(`${name} contains forbidden HTML, newline, control, or BiDi characters`);
|
|
61
|
+
if (forbidSpace && /\s/.test(s)) throw new Error(`${name} must not contain whitespace`);
|
|
62
|
+
if (utf8ByteLength(s) > maxBytes) throw new Error(`${name} exceeds maximum length of ${maxBytes} UTF-8 bytes`);
|
|
63
|
+
return s;
|
|
64
|
+
}
|
|
65
|
+
function assertBareBridgeDid(val, name = "bridge") {
|
|
66
|
+
const s = assertTrimmedSingleLine(val, name, 64, true);
|
|
67
|
+
if (/^did:abt:/i.test(s)) throw new Error(`${name} must be a bare base58btc DID without did:abt: prefix`);
|
|
68
|
+
if (!BARE_BASE58_DID_RE.test(s)) throw new Error(`${name} must be a bare base58btc OCAP DID`);
|
|
69
|
+
return s;
|
|
70
|
+
}
|
|
71
|
+
function assertSafeChainId(val, name = "ocapChainId") {
|
|
72
|
+
const s = assertTrimmedSingleLine(val, name, 64, true);
|
|
73
|
+
if (!SAFE_CHAIN_ID_RE.test(s)) throw new Error(`${name} contains invalid characters`);
|
|
74
|
+
return s;
|
|
75
|
+
}
|
|
76
|
+
function assertBoundedPlainText(val, name, maxBytes = MAX_PROPOSAL_SUMMARY_BYTES) {
|
|
77
|
+
const s = assertWellFormedString(val, name);
|
|
78
|
+
if (s.trim().length === 0) throw new Error(`${name} must not be empty`);
|
|
79
|
+
if (FORBIDDEN_PLAIN_TEXT_RE.test(s)) throw new Error(`${name} contains forbidden HTML (<, >), control, or BiDi override characters`);
|
|
80
|
+
if (utf8ByteLength(s) > maxBytes) throw new Error(`${name} exceeds maximum length of ${maxBytes} UTF-8 bytes`);
|
|
81
|
+
return s;
|
|
82
|
+
}
|
|
83
|
+
function assertValidProposalTitle(val, name = "title") {
|
|
84
|
+
const s = assertTrimmedSingleLine(val, name, MAX_PROPOSAL_TITLE_CHARS * 4, false);
|
|
85
|
+
if ([...s].length > MAX_PROPOSAL_TITLE_CHARS) throw new Error(`${name} exceeds maximum length of ${MAX_PROPOSAL_TITLE_CHARS} characters`);
|
|
86
|
+
return s;
|
|
87
|
+
}
|
|
88
|
+
function assertHttpUrl(val, name, httpsOnly = false, maxBytes = 256) {
|
|
89
|
+
const s = assertTrimmedSingleLine(val, name, maxBytes, true);
|
|
90
|
+
if (/["'`\\]/.test(s)) throw new Error(`${name} contains forbidden quote or backslash characters`);
|
|
91
|
+
let parsed;
|
|
92
|
+
try {
|
|
93
|
+
parsed = new URL(s);
|
|
94
|
+
} catch {
|
|
95
|
+
throw new Error(`${name} must be a valid HTTP(S) URL`);
|
|
96
|
+
}
|
|
97
|
+
if (httpsOnly ? parsed.protocol !== "https:" : parsed.protocol !== "https:" && parsed.protocol !== "http:") throw new Error(`${name} must use ${httpsOnly ? "https" : "http or https"} scheme`);
|
|
98
|
+
if (!parsed.hostname || parsed.username || parsed.password) throw new Error(`${name} must not contain URL credentials`);
|
|
99
|
+
return s;
|
|
100
|
+
}
|
|
101
|
+
function assertValidRationaleUrl(val, name = "rationaleUrl") {
|
|
102
|
+
return assertHttpUrl(val, name, true, MAX_PROPOSAL_RATIONALE_URL_BYTES);
|
|
103
|
+
}
|
|
104
|
+
/** Pure EIP-55 checksum encoder and validator (accepts all-lowercase or valid EIP-55 checksum, matching viem getAddress). */
|
|
105
|
+
function checksumEthAddress(raw, name = "address") {
|
|
106
|
+
const s = assertWellFormedString(raw, name);
|
|
107
|
+
if (!/^0x[0-9a-fA-F]{40}$/.test(s)) throw new Error(`${name} must be a 20-byte 0x hex Ethereum address`);
|
|
108
|
+
const body = s.slice(2);
|
|
109
|
+
const lower = body.toLowerCase();
|
|
110
|
+
const hashHex = bytesToHex(keccak_256(utf8ToBytes(lower)));
|
|
111
|
+
let checksummed = "0x";
|
|
112
|
+
for (let i = 0; i < 40; i++) {
|
|
113
|
+
const ch = lower[i];
|
|
114
|
+
checksummed += Number.parseInt(hashHex[i], 16) >= 8 ? ch.toUpperCase() : ch;
|
|
115
|
+
}
|
|
116
|
+
if (body !== lower && s !== checksummed) throw new Error(`${name} has an invalid EIP-55 checksum`);
|
|
117
|
+
return checksummed;
|
|
118
|
+
}
|
|
119
|
+
function checkedNonZeroAddress(raw, name) {
|
|
120
|
+
const checksummed = checksumEthAddress(raw, name);
|
|
121
|
+
if (checksummed === ZERO_ADDRESS) throw new Error(`${name} cannot be zero address`);
|
|
122
|
+
return checksummed;
|
|
123
|
+
}
|
|
124
|
+
function checkedBytes32(raw, name) {
|
|
125
|
+
const s = assertWellFormedString(raw, name);
|
|
126
|
+
if (!/^0x[0-9a-fA-F]{64}$/.test(s)) throw new Error(`${name} must be a 32-byte 0x hex string`);
|
|
127
|
+
return `0x${s.slice(2).toLowerCase()}`;
|
|
128
|
+
}
|
|
129
|
+
function checkedBytes4(raw, name) {
|
|
130
|
+
const s = assertWellFormedString(raw, name);
|
|
131
|
+
if (!/^0x[0-9a-fA-F]{8}$/.test(s)) throw new Error(`${name} must be a 4-byte 0x hex selector`);
|
|
132
|
+
return `0x${s.slice(2).toLowerCase()}`;
|
|
133
|
+
}
|
|
134
|
+
function checkedNonEmptyHex(raw, name, maxBytes) {
|
|
135
|
+
const s = assertWellFormedString(raw, name);
|
|
136
|
+
if (!/^0x(?:[0-9a-fA-F]{2})+$/.test(s)) throw new Error(`${name} must be a non-empty even-length 0x hex string`);
|
|
137
|
+
if ((s.length - 2) / 2 > maxBytes) throw new Error(`${name} exceeds ${maxBytes} bytes`);
|
|
138
|
+
return `0x${s.slice(2).toLowerCase()}`;
|
|
139
|
+
}
|
|
140
|
+
function assertBigIntRange(val, name, min, max) {
|
|
141
|
+
if (typeof val !== "bigint") throw new Error(`${name} must be a bigint`);
|
|
142
|
+
if (val < min || val > max) throw new Error(`${name} out of range [${min}, ${max}]`);
|
|
143
|
+
return val;
|
|
144
|
+
}
|
|
145
|
+
function parseDecimalBigInt(val, name, min, max) {
|
|
146
|
+
if (typeof val === "bigint") return assertBigIntRange(val, name, min, max);
|
|
147
|
+
if (typeof val !== "string" || !/^(?:0|[1-9][0-9]{0,77})$/.test(val)) throw new Error(`${name} must be a canonical base-10 unsigned integer string`);
|
|
148
|
+
return assertBigIntRange(BigInt(val), name, min, max);
|
|
149
|
+
}
|
|
150
|
+
function assertSafeUint(val, name, min, max) {
|
|
151
|
+
if (typeof val !== "number" || !Number.isSafeInteger(val) || val < min || val > max) throw new Error(`${name} must be a safe integer in [${min}, ${max}]`);
|
|
152
|
+
return val;
|
|
153
|
+
}
|
|
154
|
+
/** Sorts checksummed Ethereum addresses strictly ascending by numeric 160-bit value, rejecting duplicates. */
|
|
155
|
+
function sortStrictChecksumAddresses(addresses, label = "addresses") {
|
|
156
|
+
const sorted = [...addresses.map((a, i) => checkedNonZeroAddress(a, `${label}[${i}]`))].sort((a, b) => BigInt(a) < BigInt(b) ? -1 : BigInt(a) > BigInt(b) ? 1 : 0);
|
|
157
|
+
for (let i = 1; i < sorted.length; i++) if (sorted[i] === sorted[i - 1]) throw new Error(`duplicate address ${sorted[i]} in ${label}`);
|
|
158
|
+
return sorted;
|
|
159
|
+
}
|
|
160
|
+
function normalizeUncompressedSecp256k1Pk(pk) {
|
|
161
|
+
const s = assertWellFormedString(pk, "pk");
|
|
162
|
+
const m = /^(?:0x)?([0-9a-fA-F]{128})$/.exec(s) ?? /^(?:0x)?04([0-9a-fA-F]{128})$/.exec(s);
|
|
163
|
+
if (!m?.[1]) throw new Error("secp256k1 public key must be 64-byte (128 hex) or 65-byte (04 + 128 hex) uncompressed hex");
|
|
164
|
+
const normalized = m[1].toLowerCase();
|
|
165
|
+
secp256k1.Point.fromHex(`04${normalized}`);
|
|
166
|
+
return `0x${normalized}`;
|
|
167
|
+
}
|
|
168
|
+
function ethAddressFromUncompressedPk(pk) {
|
|
169
|
+
return checkedNonZeroAddress(`0x${bytesToHex(keccak_256(hexToBytes(normalizeUncompressedSecp256k1Pk(pk).slice(2))).subarray(12))}`, "derived pk address");
|
|
170
|
+
}
|
|
171
|
+
/** Deterministic 66-character `statedb.evidence` key (`gi:<63hex>`) for the per-bridge proposal ring index. */
|
|
172
|
+
function bridgeGovIndexKey(bridge) {
|
|
173
|
+
const normalizedBridge = assertBareBridgeDid(bridge, "bridge");
|
|
174
|
+
return `${BRIDGE_GOV_INDEX_TAG}${bytesToHex(keccak_256(concatBytes(utf8ToBytes("arc-bridge:gov-index:"), utf8ToBytes(normalizedBridge)))).slice(0, 63)}`;
|
|
175
|
+
}
|
|
176
|
+
/** Deterministic 66-character `statedb.evidence` key (`gd:<63hex>`) for a bridge governance proposal document. */
|
|
177
|
+
function bridgeGovDocKey(bridge, proposalId) {
|
|
178
|
+
const normalizedBridge = assertBareBridgeDid(bridge, "bridge");
|
|
179
|
+
const idBytes = hexToBytes(checkedBytes32(proposalId, "proposalId").slice(2));
|
|
180
|
+
return `${BRIDGE_GOV_DOC_TAG}${bytesToHex(keccak_256(concatBytes(utf8ToBytes("arc-bridge:gov-doc:"), utf8ToBytes(normalizedBridge), idBytes))).slice(0, 63)}`;
|
|
181
|
+
}
|
|
182
|
+
function isBridgeGovKey(key) {
|
|
183
|
+
return typeof key === "string" && BRIDGE_GOV_KEY_PATTERN.test(key);
|
|
184
|
+
}
|
|
185
|
+
function inBridgeGovKeySpace(key) {
|
|
186
|
+
return typeof key === "string" && /^g[id]:/i.test(key.trim());
|
|
187
|
+
}
|
|
188
|
+
/** Canonical JSON serializer (lexicographically sorted keys, finite numbers only, no undefined/BigInt). */
|
|
189
|
+
function canonicalJson(value) {
|
|
190
|
+
if (value === null || typeof value === "boolean") return JSON.stringify(value);
|
|
191
|
+
if (typeof value === "number") {
|
|
192
|
+
if (!Number.isFinite(value)) throw new Error("canonicalJson: non-finite number");
|
|
193
|
+
return JSON.stringify(value);
|
|
194
|
+
}
|
|
195
|
+
if (typeof value === "string") return JSON.stringify(value);
|
|
196
|
+
if (Array.isArray(value)) return `[${value.map(canonicalJson).join(",")}]`;
|
|
197
|
+
if (typeof value === "object") {
|
|
198
|
+
const record = value;
|
|
199
|
+
const parts = [];
|
|
200
|
+
for (const k of Object.keys(record).sort()) {
|
|
201
|
+
const v = record[k];
|
|
202
|
+
if (v === void 0) throw new Error(`canonicalJson: undefined at key "${k}"`);
|
|
203
|
+
parts.push(`${JSON.stringify(k)}:${canonicalJson(v)}`);
|
|
204
|
+
}
|
|
205
|
+
return `{${parts.join(",")}}`;
|
|
206
|
+
}
|
|
207
|
+
throw new Error(`canonicalJson: unsupported type ${typeof value}`);
|
|
208
|
+
}
|
|
209
|
+
/** Converts `bigint` leaves to decimal strings while omitting `undefined` object properties. */
|
|
210
|
+
function toJsonSafeValue(value) {
|
|
211
|
+
if (typeof value === "bigint") return value.toString(10);
|
|
212
|
+
if (value === null || typeof value === "boolean" || typeof value === "number" || typeof value === "string") return value;
|
|
213
|
+
if (Array.isArray(value)) return value.map(toJsonSafeValue);
|
|
214
|
+
if (typeof value === "object") {
|
|
215
|
+
const src = value;
|
|
216
|
+
const out = {};
|
|
217
|
+
for (const key of Object.keys(src)) if (src[key] !== void 0) out[key] = toJsonSafeValue(src[key]);
|
|
218
|
+
return out;
|
|
219
|
+
}
|
|
220
|
+
throw new Error(`Unsupported value type in proposal serialization: ${typeof value}`);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
//#endregion
|
|
224
|
+
export { BRIDGE_GOV_DOC_TAG, BRIDGE_GOV_INDEX_TAG, BRIDGE_GOV_KEY_PATTERN, EVM_GOV_CONFIG_HASH_PREFIX, EVM_PROPOSAL_HASH_PREFIX, MAX_EVM_GOV_ROSTER_JSON_BYTES, MAX_EVM_SIGNERS, MAX_GOV_DOC_JSON_BYTES, MAX_OCAP_DELAY_SEC, MAX_OCAP_PAUSERS, MAX_OCAP_VALIDATORS, MAX_PROPOSAL_JSON_BYTES, MAX_PROPOSAL_RATIONALE_URL_BYTES, MAX_PROPOSAL_SUMMARY_BYTES, MAX_PROPOSAL_TITLE_CHARS, MAX_SAFE_BIGINT, MAX_U256, MAX_U64, MIN_OCAP_VALIDATORS, OCAP_PROPOSAL_HASH_PREFIX, ZERO_ADDRESS, ZERO_BYTES32, assertAllowedKeys, assertBareBridgeDid, assertBigIntRange, assertBoundedPlainText, assertHttpUrl, assertPlainObject, assertSafeChainId, assertSafeUint, assertTrimmedSingleLine, assertValidProposalTitle, assertValidRationaleUrl, assertWellFormedString, bridgeGovDocKey, bridgeGovIndexKey, canonicalJson, checkedBytes32, checkedBytes4, checkedNonEmptyHex, checkedNonZeroAddress, checksumEthAddress, ethAddressFromUncompressedPk, inBridgeGovKeySpace, isBridgeGovKey, normalizeUncompressedSecp256k1Pk, parseDecimalBigInt, sortStrictChecksumAddresses, toJsonSafeValue, utf8ByteLength };
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { BytesType } from "@ocap/util";
|
|
2
|
+
|
|
3
|
+
//#region src/bridge-governance/membership.d.ts
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* EIP-712 structs the on-chain bridge governance (bridge/docs/ocap-protocols.md §v2.2) verifies on the OCAP side:
|
|
7
|
+
* `BridgeMembership` (operator consent / join / leave) and `BridgeOwnerAttestation` (Ethereum owner proof).
|
|
8
|
+
*
|
|
9
|
+
* This is a port of `membership.ts` in `@arcblock/bridge-types` (bridge/types/src/membership.ts). Core packages cannot
|
|
10
|
+
* depend on the private bridge workspace, so the logic is duplicated on purpose and a parity test
|
|
11
|
+
* (core/mcrypto/tests/bridge-governance.spec.ts) runs this port against the vector file
|
|
12
|
+
* bridge/types/vectors/membership.json, which is generated from viem (what wallets run). Change both together.
|
|
13
|
+
*
|
|
14
|
+
* Domain: `{ name: "ArcBridgeOcap", version: "1" }` with NO chainId / verifyingContract; the OCAP chain and the bridge
|
|
15
|
+
* are carried inside the struct (`ocapChainId`, `bridge`), so an approval cannot be replayed across chains or bridges.
|
|
16
|
+
*/
|
|
17
|
+
declare const BRIDGE_GOV_DOMAIN_NAME = "ArcBridgeOcap";
|
|
18
|
+
declare const BRIDGE_GOV_DOMAIN_VERSION = "1";
|
|
19
|
+
declare const BRIDGE_MEMBERSHIP_TYPE_STRING = "BridgeMembership(string ocapChainId,string bridge,uint64 epoch,address[] validators,uint32 threshold,uint64 activeFrom,uint64 voucherValidity,bytes32 endpointsHash,uint8 action)";
|
|
20
|
+
declare const BRIDGE_OWNER_ATTESTATION_TYPE_STRING = "BridgeOwnerAttestation(string ocapChainId,bytes32 salt,string ocapToken,uint256 ethChainId,address gateway,address ethToken)";
|
|
21
|
+
/** `action` of a BridgeMembership: CREATE = epoch 1 consent, JOIN / LEAVE = epoch change. */
|
|
22
|
+
declare const BRIDGE_MEMBERSHIP_ACTION: {
|
|
23
|
+
readonly CREATE: 0;
|
|
24
|
+
readonly JOIN: 1;
|
|
25
|
+
readonly LEAVE: 2;
|
|
26
|
+
};
|
|
27
|
+
interface BridgeMembershipMessage {
|
|
28
|
+
ocapChainId: string;
|
|
29
|
+
bridge: string;
|
|
30
|
+
epoch: bigint | number | string;
|
|
31
|
+
/** Strictly ascending (numeric) and unique: the signer signs exactly this order. */
|
|
32
|
+
validators: string[];
|
|
33
|
+
threshold: number;
|
|
34
|
+
activeFrom: bigint | number | string;
|
|
35
|
+
voucherValidity: bigint | number | string;
|
|
36
|
+
/** `computeBridgeEndpointsHash` of the endpoints of `validators`, in the same order */
|
|
37
|
+
endpointsHash: string;
|
|
38
|
+
action: number;
|
|
39
|
+
}
|
|
40
|
+
interface BridgeOwnerAttestationMessage {
|
|
41
|
+
ocapChainId: string;
|
|
42
|
+
salt: string;
|
|
43
|
+
ocapToken: string;
|
|
44
|
+
ethChainId: bigint | number | string;
|
|
45
|
+
gateway: string;
|
|
46
|
+
ethToken: string;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* `keccak256(keccak256(endpoint_0) || keccak256(endpoint_1) || ...)` over the endpoints of the validators in the order
|
|
50
|
+
* of the signed `validators` array. It binds every listed operator to the URL it is reachable at, so a creator cannot
|
|
51
|
+
* pair a victim operator with another URL.
|
|
52
|
+
*/
|
|
53
|
+
declare function computeBridgeEndpointsHash(endpoints: string[]): string;
|
|
54
|
+
declare function computeBridgeMembershipDigest(m: BridgeMembershipMessage): Uint8Array;
|
|
55
|
+
declare function computeBridgeOwnerAttestationDigest(m: BridgeOwnerAttestationMessage): Uint8Array;
|
|
56
|
+
/** Ethereum address (lowercase 0x) of an uncompressed (64/65 bytes) or compressed secp256k1 public key. */
|
|
57
|
+
declare function ethAddressOfPublicKey(pk: BytesType): string;
|
|
58
|
+
interface RecoveredBridgeSigner {
|
|
59
|
+
/** lowercase 0x address */
|
|
60
|
+
address: string;
|
|
61
|
+
/** 65-byte uncompressed public key, 0x04 prefixed */
|
|
62
|
+
publicKey: Uint8Array;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Recover the signer of a canonical 65-byte `r || s || v` signature (`v` in {27, 28}, low-S). Returns null on anything
|
|
66
|
+
* else, so a malleable or malformed signature never recovers to an address.
|
|
67
|
+
*/
|
|
68
|
+
declare function recoverBridgeSigner(digest: Uint8Array, signature: string): RecoveredBridgeSigner | null;
|
|
69
|
+
/** Sign a governance digest with a secp256k1 secret key; returns the 65-byte `0x{r}{s}{v}` signature. */
|
|
70
|
+
declare function signBridgeDigest(digest: Uint8Array, sk: BytesType): string;
|
|
71
|
+
declare const toHexDigest: (digest: Uint8Array) => string;
|
|
72
|
+
type BridgeKeyPart = {
|
|
73
|
+
uint: bigint | number | string;
|
|
74
|
+
} | {
|
|
75
|
+
address: string;
|
|
76
|
+
} | {
|
|
77
|
+
bytes32: string;
|
|
78
|
+
} | {
|
|
79
|
+
text: string;
|
|
80
|
+
};
|
|
81
|
+
/**
|
|
82
|
+
* keccak256 of `utf8(prefix) || words`: the key preimage helper for the `arc-bridge:*` evidence keys. Every dynamic part
|
|
83
|
+
* is a fixed-width word (uint256 / address / bytes32) or the trailing DID string, so two different tuples never share a
|
|
84
|
+
* preimage. Returns a `0x` + 64 hex string (the evidence table key shape).
|
|
85
|
+
*/
|
|
86
|
+
declare function bridgeEvidenceKey(prefix: string, parts: BridgeKeyPart[]): string;
|
|
87
|
+
/**
|
|
88
|
+
* Evidence keys of a bridge release (`deposit_token_v2` kind 1/2/3) are SELF-IDENTIFYING: a 3-character tag (`rt:` tombstone, `rb:` bucket) and the
|
|
89
|
+
* first 63 hex digits of the keccak digest of the `bridgeEvidenceKey` preimage, 66 characters in total.
|
|
90
|
+
*
|
|
91
|
+
* Legacy rollup v1 protocols store evidence rows at a caller-chosen key validated only by `patterns.txHash`
|
|
92
|
+
* (`^(0x)?[0-9a-fA-F]{64}$`). `r` and `:` are not hex digits, so no key a v1 tx (or any other `txHash`-validated input) can
|
|
93
|
+
* carry ever lands in this key space, and the gate can tell a release row by its key alone. 66 characters is exactly the
|
|
94
|
+
* width of a `0x` + 64 hex key, so every statedb backend that stores today's evidence keys stores these. The `:` also
|
|
95
|
+
* keeps the key from ever parsing as a DID (base58 has no `:`). 252 bits of keccak keep collision resistance at 2^126.
|
|
96
|
+
*/
|
|
97
|
+
declare const BRIDGE_RELEASE_TOMBSTONE_TAG = "rt:";
|
|
98
|
+
declare const BRIDGE_RELEASE_BUCKET_TAG = "rb:";
|
|
99
|
+
/** a canonical release key: tag + 63 lowercase hex */
|
|
100
|
+
declare const BRIDGE_RELEASE_KEY_PATTERN: RegExp;
|
|
101
|
+
/**
|
|
102
|
+
* Tombstone key of a release: `rt:` + keccak256("arc-bridge:release:" || uint kind || bytes32 evidence || uint ordinal ||
|
|
103
|
+
* bridge). `evidence` is a `0x` bytes32 (lowercased here); `bridge` the canonical bridge address.
|
|
104
|
+
*/
|
|
105
|
+
declare function bridgeReleaseTombstoneKey(bridge: string, kind: number | bigint | string, evidence: string, ordinal: number | bigint | string): string;
|
|
106
|
+
/** Key of slot `slot` of ring `ring` (0 = deposit, 1 = refund) of `bridge`: `rb:` + keccak256("arc-bridge:release-bucket:" || uint ring || uint slot || bridge). */
|
|
107
|
+
declare function bridgeReleaseBucketKey(bridge: string, ring: number, slot: number): string;
|
|
108
|
+
/** Whether `key` is a canonical release key (tombstone or bucket). */
|
|
109
|
+
declare const isBridgeReleaseKey: (key: unknown) => boolean;
|
|
110
|
+
/**
|
|
111
|
+
* Whether `key` is in the release key space in ANY spelling (case, surrounding whitespace): what the gate refuses to any
|
|
112
|
+
* tx type but a bridge release.
|
|
113
|
+
*/
|
|
114
|
+
declare const inBridgeReleaseKeySpace: (key: unknown) => boolean;
|
|
115
|
+
//#endregion
|
|
116
|
+
export { BRIDGE_GOV_DOMAIN_NAME, BRIDGE_GOV_DOMAIN_VERSION, BRIDGE_MEMBERSHIP_ACTION, BRIDGE_MEMBERSHIP_TYPE_STRING, BRIDGE_OWNER_ATTESTATION_TYPE_STRING, BRIDGE_RELEASE_BUCKET_TAG, BRIDGE_RELEASE_KEY_PATTERN, BRIDGE_RELEASE_TOMBSTONE_TAG, BridgeKeyPart, BridgeMembershipMessage, BridgeOwnerAttestationMessage, RecoveredBridgeSigner, bridgeEvidenceKey, bridgeReleaseBucketKey, bridgeReleaseTombstoneKey, computeBridgeEndpointsHash, computeBridgeMembershipDigest, computeBridgeOwnerAttestationDigest, ethAddressOfPublicKey, inBridgeReleaseKeySpace, isBridgeReleaseKey, recoverBridgeSigner, signBridgeDigest, toHexDigest };
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import { secp256k1 } from "@noble/curves/secp256k1.js";
|
|
2
|
+
import { keccak_256 } from "@noble/hashes/sha3.js";
|
|
3
|
+
import { bytesToHex } from "@noble/hashes/utils.js";
|
|
4
|
+
import { toUint8Array } from "@ocap/util";
|
|
5
|
+
|
|
6
|
+
//#region src/bridge-governance/membership.ts
|
|
7
|
+
/**
|
|
8
|
+
* EIP-712 structs the on-chain bridge governance (bridge/docs/ocap-protocols.md §v2.2) verifies on the OCAP side:
|
|
9
|
+
* `BridgeMembership` (operator consent / join / leave) and `BridgeOwnerAttestation` (Ethereum owner proof).
|
|
10
|
+
*
|
|
11
|
+
* This is a port of `membership.ts` in `@arcblock/bridge-types` (bridge/types/src/membership.ts). Core packages cannot
|
|
12
|
+
* depend on the private bridge workspace, so the logic is duplicated on purpose and a parity test
|
|
13
|
+
* (core/mcrypto/tests/bridge-governance.spec.ts) runs this port against the vector file
|
|
14
|
+
* bridge/types/vectors/membership.json, which is generated from viem (what wallets run). Change both together.
|
|
15
|
+
*
|
|
16
|
+
* Domain: `{ name: "ArcBridgeOcap", version: "1" }` with NO chainId / verifyingContract; the OCAP chain and the bridge
|
|
17
|
+
* are carried inside the struct (`ocapChainId`, `bridge`), so an approval cannot be replayed across chains or bridges.
|
|
18
|
+
*/
|
|
19
|
+
const BRIDGE_GOV_DOMAIN_NAME = "ArcBridgeOcap";
|
|
20
|
+
const BRIDGE_GOV_DOMAIN_VERSION = "1";
|
|
21
|
+
const BRIDGE_MEMBERSHIP_TYPE_STRING = "BridgeMembership(string ocapChainId,string bridge,uint64 epoch,address[] validators,uint32 threshold,uint64 activeFrom,uint64 voucherValidity,bytes32 endpointsHash,uint8 action)";
|
|
22
|
+
const BRIDGE_OWNER_ATTESTATION_TYPE_STRING = "BridgeOwnerAttestation(string ocapChainId,bytes32 salt,string ocapToken,uint256 ethChainId,address gateway,address ethToken)";
|
|
23
|
+
/** `action` of a BridgeMembership: CREATE = epoch 1 consent, JOIN / LEAVE = epoch change. */
|
|
24
|
+
const BRIDGE_MEMBERSHIP_ACTION = {
|
|
25
|
+
CREATE: 0,
|
|
26
|
+
JOIN: 1,
|
|
27
|
+
LEAVE: 2
|
|
28
|
+
};
|
|
29
|
+
const utf8 = (s) => new Uint8Array(Buffer.from(s, "utf8"));
|
|
30
|
+
const keccakUtf8 = (s) => keccak_256(utf8(s));
|
|
31
|
+
const concat = (...parts) => new Uint8Array(Buffer.concat(parts));
|
|
32
|
+
const DOMAIN_TYPEHASH = keccakUtf8("EIP712Domain(string name,string version)");
|
|
33
|
+
const MEMBERSHIP_TYPEHASH = keccakUtf8(BRIDGE_MEMBERSHIP_TYPE_STRING);
|
|
34
|
+
const ATTESTATION_TYPEHASH = keccakUtf8(BRIDGE_OWNER_ATTESTATION_TYPE_STRING);
|
|
35
|
+
const DOMAIN_SEPARATOR = keccak_256(concat(DOMAIN_TYPEHASH, keccakUtf8(BRIDGE_GOV_DOMAIN_NAME), keccakUtf8(BRIDGE_GOV_DOMAIN_VERSION)));
|
|
36
|
+
function uintWord(value, bits, name) {
|
|
37
|
+
let n;
|
|
38
|
+
try {
|
|
39
|
+
n = typeof value === "bigint" ? value : BigInt(value);
|
|
40
|
+
} catch {
|
|
41
|
+
throw new Error(`${name} is not an integer`);
|
|
42
|
+
}
|
|
43
|
+
if (n < 0n || n >= 1n << BigInt(bits)) throw new Error(`${name} does not fit uint${bits}`);
|
|
44
|
+
return new Uint8Array(Buffer.from(n.toString(16).padStart(64, "0"), "hex"));
|
|
45
|
+
}
|
|
46
|
+
function addressWord(value, name) {
|
|
47
|
+
if (typeof value !== "string" || !/^0x[0-9a-fA-F]{40}$/.test(value)) throw new Error(`${name} is not an address`);
|
|
48
|
+
return new Uint8Array(Buffer.from(value.slice(2).toLowerCase().padStart(64, "0"), "hex"));
|
|
49
|
+
}
|
|
50
|
+
function bytes32Word(value, name) {
|
|
51
|
+
if (typeof value !== "string" || !/^0x[0-9a-fA-F]{64}$/.test(value)) throw new Error(`${name} is not a bytes32`);
|
|
52
|
+
return new Uint8Array(Buffer.from(value.slice(2), "hex"));
|
|
53
|
+
}
|
|
54
|
+
function digestOf(structHash) {
|
|
55
|
+
return keccak_256(concat(new Uint8Array([25, 1]), DOMAIN_SEPARATOR, structHash));
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* `keccak256(keccak256(endpoint_0) || keccak256(endpoint_1) || ...)` over the endpoints of the validators in the order
|
|
59
|
+
* of the signed `validators` array. It binds every listed operator to the URL it is reachable at, so a creator cannot
|
|
60
|
+
* pair a victim operator with another URL.
|
|
61
|
+
*/
|
|
62
|
+
function computeBridgeEndpointsHash(endpoints) {
|
|
63
|
+
if (!Array.isArray(endpoints)) throw new Error("endpoints is not an array");
|
|
64
|
+
return `0x${bytesToHex(keccak_256(concat(...endpoints.map((e) => keccakUtf8(String(e))))))}`;
|
|
65
|
+
}
|
|
66
|
+
function computeBridgeMembershipDigest(m) {
|
|
67
|
+
if (!Array.isArray(m.validators)) throw new Error("validators is not an array");
|
|
68
|
+
const validators = keccak_256(concat(...m.validators.map((a, i) => addressWord(a, `validators[${i}]`))));
|
|
69
|
+
return digestOf(keccak_256(concat(MEMBERSHIP_TYPEHASH, keccakUtf8(m.ocapChainId), keccakUtf8(m.bridge), uintWord(m.epoch, 64, "epoch"), validators, uintWord(m.threshold, 32, "threshold"), uintWord(m.activeFrom, 64, "activeFrom"), uintWord(m.voucherValidity, 64, "voucherValidity"), bytes32Word(m.endpointsHash, "endpointsHash"), uintWord(m.action, 8, "action"))));
|
|
70
|
+
}
|
|
71
|
+
function computeBridgeOwnerAttestationDigest(m) {
|
|
72
|
+
return digestOf(keccak_256(concat(ATTESTATION_TYPEHASH, keccakUtf8(m.ocapChainId), bytes32Word(m.salt, "salt"), keccakUtf8(m.ocapToken), uintWord(m.ethChainId, 256, "ethChainId"), addressWord(m.gateway, "gateway"), addressWord(m.ethToken, "ethToken"))));
|
|
73
|
+
}
|
|
74
|
+
/** Ethereum address (lowercase 0x) of an uncompressed (64/65 bytes) or compressed secp256k1 public key. */
|
|
75
|
+
function ethAddressOfPublicKey(pk) {
|
|
76
|
+
const bytes = toUint8Array(pk);
|
|
77
|
+
return `0x${bytesToHex(keccak_256(bytes.byteLength === 64 ? bytes : bytes.byteLength === 65 ? bytes.slice(1) : secp256k1.Point.fromBytes(bytes).toBytes(false).slice(1)).slice(12))}`;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Recover the signer of a canonical 65-byte `r || s || v` signature (`v` in {27, 28}, low-S). Returns null on anything
|
|
81
|
+
* else, so a malleable or malformed signature never recovers to an address.
|
|
82
|
+
*/
|
|
83
|
+
function recoverBridgeSigner(digest, signature) {
|
|
84
|
+
if (typeof signature !== "string" || !/^0x[0-9a-fA-F]{130}$/.test(signature)) return null;
|
|
85
|
+
const hex = signature.slice(2);
|
|
86
|
+
const v = Number.parseInt(hex.slice(128, 130), 16);
|
|
87
|
+
if (v !== 27 && v !== 28) return null;
|
|
88
|
+
try {
|
|
89
|
+
const sig = secp256k1.Signature.fromHex(hex.slice(0, 128), "compact").addRecoveryBit(v - 27);
|
|
90
|
+
if (sig.hasHighS()) return null;
|
|
91
|
+
const publicKey = sig.recoverPublicKey(digest).toBytes(false);
|
|
92
|
+
return {
|
|
93
|
+
address: ethAddressOfPublicKey(publicKey),
|
|
94
|
+
publicKey
|
|
95
|
+
};
|
|
96
|
+
} catch {
|
|
97
|
+
return null;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
/** Sign a governance digest with a secp256k1 secret key; returns the 65-byte `0x{r}{s}{v}` signature. */
|
|
101
|
+
function signBridgeDigest(digest, sk) {
|
|
102
|
+
const recovered = secp256k1.sign(digest, toUint8Array(sk), {
|
|
103
|
+
prehash: false,
|
|
104
|
+
format: "recovered"
|
|
105
|
+
});
|
|
106
|
+
const sig = secp256k1.Signature.fromBytes(recovered, "recovered");
|
|
107
|
+
const v = (27 + sig.recovery).toString(16).padStart(2, "0");
|
|
108
|
+
return `0x${sig.toHex("compact")}${v}`;
|
|
109
|
+
}
|
|
110
|
+
const toHexDigest = (digest) => `0x${bytesToHex(digest)}`;
|
|
111
|
+
/**
|
|
112
|
+
* keccak256 of `utf8(prefix) || words`: the key preimage helper for the `arc-bridge:*` evidence keys. Every dynamic part
|
|
113
|
+
* is a fixed-width word (uint256 / address / bytes32) or the trailing DID string, so two different tuples never share a
|
|
114
|
+
* preimage. Returns a `0x` + 64 hex string (the evidence table key shape).
|
|
115
|
+
*/
|
|
116
|
+
function bridgeEvidenceKey(prefix, parts) {
|
|
117
|
+
const chunks = [utf8(prefix)];
|
|
118
|
+
parts.forEach((p, i) => {
|
|
119
|
+
if ("uint" in p) chunks.push(uintWord(p.uint, 256, `part[${i}]`));
|
|
120
|
+
else if ("address" in p) chunks.push(addressWord(p.address, `part[${i}]`));
|
|
121
|
+
else if ("bytes32" in p) chunks.push(bytes32Word(p.bytes32, `part[${i}]`));
|
|
122
|
+
else {
|
|
123
|
+
if (i !== parts.length - 1) throw new Error("text part must be last");
|
|
124
|
+
chunks.push(utf8(p.text));
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
return `0x${bytesToHex(keccak_256(concat(...chunks)))}`;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Evidence keys of a bridge release (`deposit_token_v2` kind 1/2/3) are SELF-IDENTIFYING: a 3-character tag (`rt:` tombstone, `rb:` bucket) and the
|
|
131
|
+
* first 63 hex digits of the keccak digest of the `bridgeEvidenceKey` preimage, 66 characters in total.
|
|
132
|
+
*
|
|
133
|
+
* Legacy rollup v1 protocols store evidence rows at a caller-chosen key validated only by `patterns.txHash`
|
|
134
|
+
* (`^(0x)?[0-9a-fA-F]{64}$`). `r` and `:` are not hex digits, so no key a v1 tx (or any other `txHash`-validated input) can
|
|
135
|
+
* carry ever lands in this key space, and the gate can tell a release row by its key alone. 66 characters is exactly the
|
|
136
|
+
* width of a `0x` + 64 hex key, so every statedb backend that stores today's evidence keys stores these. The `:` also
|
|
137
|
+
* keeps the key from ever parsing as a DID (base58 has no `:`). 252 bits of keccak keep collision resistance at 2^126.
|
|
138
|
+
*/
|
|
139
|
+
const BRIDGE_RELEASE_TOMBSTONE_TAG = "rt:";
|
|
140
|
+
const BRIDGE_RELEASE_BUCKET_TAG = "rb:";
|
|
141
|
+
const RELEASE_TOMBSTONE_DOMAIN = "arc-bridge:release:";
|
|
142
|
+
const RELEASE_BUCKET_DOMAIN = "arc-bridge:release-bucket:";
|
|
143
|
+
/** a canonical release key: tag + 63 lowercase hex */
|
|
144
|
+
const BRIDGE_RELEASE_KEY_PATTERN = /^r[tb]:[0-9a-f]{63}$/;
|
|
145
|
+
const releaseKey = (tag, domain, parts) => `${tag}${bridgeEvidenceKey(domain, parts).slice(2, 65)}`;
|
|
146
|
+
/**
|
|
147
|
+
* Tombstone key of a release: `rt:` + keccak256("arc-bridge:release:" || uint kind || bytes32 evidence || uint ordinal ||
|
|
148
|
+
* bridge). `evidence` is a `0x` bytes32 (lowercased here); `bridge` the canonical bridge address.
|
|
149
|
+
*/
|
|
150
|
+
function bridgeReleaseTombstoneKey(bridge, kind, evidence, ordinal) {
|
|
151
|
+
return releaseKey(BRIDGE_RELEASE_TOMBSTONE_TAG, RELEASE_TOMBSTONE_DOMAIN, [
|
|
152
|
+
{ uint: kind },
|
|
153
|
+
{ bytes32: String(evidence).toLowerCase() },
|
|
154
|
+
{ uint: ordinal },
|
|
155
|
+
{ text: bridge }
|
|
156
|
+
]);
|
|
157
|
+
}
|
|
158
|
+
/** Key of slot `slot` of ring `ring` (0 = deposit, 1 = refund) of `bridge`: `rb:` + keccak256("arc-bridge:release-bucket:" || uint ring || uint slot || bridge). */
|
|
159
|
+
function bridgeReleaseBucketKey(bridge, ring, slot) {
|
|
160
|
+
return releaseKey(BRIDGE_RELEASE_BUCKET_TAG, RELEASE_BUCKET_DOMAIN, [
|
|
161
|
+
{ uint: ring },
|
|
162
|
+
{ uint: slot },
|
|
163
|
+
{ text: bridge }
|
|
164
|
+
]);
|
|
165
|
+
}
|
|
166
|
+
/** Whether `key` is a canonical release key (tombstone or bucket). */
|
|
167
|
+
const isBridgeReleaseKey = (key) => typeof key === "string" && BRIDGE_RELEASE_KEY_PATTERN.test(key);
|
|
168
|
+
/**
|
|
169
|
+
* Whether `key` is in the release key space in ANY spelling (case, surrounding whitespace): what the gate refuses to any
|
|
170
|
+
* tx type but a bridge release.
|
|
171
|
+
*/
|
|
172
|
+
const inBridgeReleaseKeySpace = (key) => typeof key === "string" && /^r[tb]:/i.test(key.trim());
|
|
173
|
+
|
|
174
|
+
//#endregion
|
|
175
|
+
export { BRIDGE_GOV_DOMAIN_NAME, BRIDGE_GOV_DOMAIN_VERSION, BRIDGE_MEMBERSHIP_ACTION, BRIDGE_MEMBERSHIP_TYPE_STRING, BRIDGE_OWNER_ATTESTATION_TYPE_STRING, BRIDGE_RELEASE_BUCKET_TAG, BRIDGE_RELEASE_KEY_PATTERN, BRIDGE_RELEASE_TOMBSTONE_TAG, bridgeEvidenceKey, bridgeReleaseBucketKey, bridgeReleaseTombstoneKey, computeBridgeEndpointsHash, computeBridgeMembershipDigest, computeBridgeOwnerAttestationDigest, ethAddressOfPublicKey, inBridgeReleaseKeySpace, isBridgeReleaseKey, recoverBridgeSigner, signBridgeDigest, toHexDigest };
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { BridgeMembershipMessage } from "./membership.mjs";
|
|
2
|
+
import { EvmGovernanceRosterConfig } from "./evm-sync.mjs";
|
|
3
|
+
|
|
4
|
+
//#region src/bridge-governance/ocap-proposals.d.ts
|
|
5
|
+
interface OcapSignerRosterEntry {
|
|
6
|
+
signer: string;
|
|
7
|
+
pk: string;
|
|
8
|
+
}
|
|
9
|
+
interface OcapMultiSigLockstep {
|
|
10
|
+
txFrom: string;
|
|
11
|
+
frozenNonce: bigint;
|
|
12
|
+
signerRoster: OcapSignerRosterEntry[];
|
|
13
|
+
unsignedTxBytesHex?: string;
|
|
14
|
+
challenge?: string;
|
|
15
|
+
}
|
|
16
|
+
interface OcapSingleSignerMetadata {
|
|
17
|
+
txFrom?: string;
|
|
18
|
+
frozenNonce?: bigint;
|
|
19
|
+
unsignedTxBytesHex?: string;
|
|
20
|
+
challenge?: string;
|
|
21
|
+
}
|
|
22
|
+
interface OcapProposeOwner {
|
|
23
|
+
newOwner: string;
|
|
24
|
+
newOwnerPk: string;
|
|
25
|
+
endpoint: string;
|
|
26
|
+
}
|
|
27
|
+
interface OcapRollupPatch {
|
|
28
|
+
minDeposit?: bigint;
|
|
29
|
+
minWithdraw?: bigint;
|
|
30
|
+
maxWithdraw?: bigint;
|
|
31
|
+
releaseDailyCap?: bigint;
|
|
32
|
+
refundDailyCap?: bigint;
|
|
33
|
+
releaseGrace?: number;
|
|
34
|
+
refundDelay?: number;
|
|
35
|
+
pausers?: string[];
|
|
36
|
+
cancelPendingEpoch?: true;
|
|
37
|
+
proposeOwner?: OcapProposeOwner;
|
|
38
|
+
cancelOwnerProposal?: true;
|
|
39
|
+
evmGovernance?: EvmGovernanceRosterConfig;
|
|
40
|
+
}
|
|
41
|
+
type OcapGovernedAction = {
|
|
42
|
+
kind: 'join_rollup';
|
|
43
|
+
validator: string;
|
|
44
|
+
endpoint: string;
|
|
45
|
+
epoch: bigint;
|
|
46
|
+
validators: string[];
|
|
47
|
+
endpoints: string[];
|
|
48
|
+
threshold: number;
|
|
49
|
+
activeFrom: bigint;
|
|
50
|
+
voucherValidity: bigint;
|
|
51
|
+
} | {
|
|
52
|
+
kind: 'leave_rollup';
|
|
53
|
+
validator: string;
|
|
54
|
+
epoch: bigint;
|
|
55
|
+
validators: string[];
|
|
56
|
+
endpoints: string[];
|
|
57
|
+
threshold: number;
|
|
58
|
+
activeFrom: bigint;
|
|
59
|
+
voucherValidity: bigint;
|
|
60
|
+
} | ({
|
|
61
|
+
kind: 'pause_rollup';
|
|
62
|
+
mode: 'lone';
|
|
63
|
+
reason: string;
|
|
64
|
+
} & OcapSingleSignerMetadata) | ({
|
|
65
|
+
kind: 'pause_rollup';
|
|
66
|
+
mode: 'quorum';
|
|
67
|
+
reason: string;
|
|
68
|
+
} & OcapMultiSigLockstep) | ({
|
|
69
|
+
kind: 'resume_rollup';
|
|
70
|
+
reason: string;
|
|
71
|
+
} & OcapMultiSigLockstep) | ({
|
|
72
|
+
kind: 'close_rollup';
|
|
73
|
+
depositCutoffEthBlock: bigint;
|
|
74
|
+
reason: string;
|
|
75
|
+
} & OcapMultiSigLockstep) | ({
|
|
76
|
+
kind: 'update_rollup';
|
|
77
|
+
patch: OcapRollupPatch;
|
|
78
|
+
} & OcapMultiSigLockstep) | ({
|
|
79
|
+
kind: 'migrate_rollup';
|
|
80
|
+
migrateKind: 'vault';
|
|
81
|
+
nextVault: string;
|
|
82
|
+
reason: string;
|
|
83
|
+
} & OcapMultiSigLockstep) | ({
|
|
84
|
+
kind: 'migrate_rollup';
|
|
85
|
+
migrateKind: 'reserve';
|
|
86
|
+
step: 'announce' | 'execute';
|
|
87
|
+
targetBridge: string;
|
|
88
|
+
reason: string;
|
|
89
|
+
} & OcapMultiSigLockstep) | ({
|
|
90
|
+
kind: 'migrate_rollup';
|
|
91
|
+
migrateKind: 'reserve';
|
|
92
|
+
step: 'cancel';
|
|
93
|
+
targetBridge: string;
|
|
94
|
+
reason: string;
|
|
95
|
+
} & OcapSingleSignerMetadata);
|
|
96
|
+
interface OcapGovernanceProposal {
|
|
97
|
+
version: 1;
|
|
98
|
+
plane: 'ocap';
|
|
99
|
+
ocapChainId: string;
|
|
100
|
+
ocapBridge: string;
|
|
101
|
+
createdAt: bigint;
|
|
102
|
+
expiresAt: bigint;
|
|
103
|
+
summary: string;
|
|
104
|
+
action: OcapGovernedAction;
|
|
105
|
+
}
|
|
106
|
+
declare function validateOcapProposal(proposal: OcapGovernanceProposal): OcapGovernanceProposal;
|
|
107
|
+
declare function coerceOcapProposal(raw: unknown): OcapGovernanceProposal;
|
|
108
|
+
declare function serializeOcapProposal(proposal: OcapGovernanceProposal): string;
|
|
109
|
+
declare function parseOcapProposal(json: string): OcapGovernanceProposal;
|
|
110
|
+
declare function computeOcapProposalId(proposal: OcapGovernanceProposal): string;
|
|
111
|
+
declare function membershipFromOcapProposal(proposal: OcapGovernanceProposal): BridgeMembershipMessage;
|
|
112
|
+
declare function recoverOcapMembershipProposalSigner(proposal: OcapGovernanceProposal, sig: string): {
|
|
113
|
+
signer: string;
|
|
114
|
+
signature: string;
|
|
115
|
+
};
|
|
116
|
+
interface ArcBlockTransactionEnvelopeFields {
|
|
117
|
+
chainId: string;
|
|
118
|
+
action: string;
|
|
119
|
+
from: string;
|
|
120
|
+
nonce: string;
|
|
121
|
+
challenge: string;
|
|
122
|
+
}
|
|
123
|
+
declare function computeArcBlockTxEip712Digest(fields: ArcBlockTransactionEnvelopeFields): Uint8Array;
|
|
124
|
+
declare function formatArcBlockTxEip191Text(fields: ArcBlockTransactionEnvelopeFields): string;
|
|
125
|
+
declare function computeArcBlockTxEip191Digest(fields: ArcBlockTransactionEnvelopeFields): Uint8Array;
|
|
126
|
+
declare function recoverArcBlockTxEnvelopeSigner(fields: ArcBlockTransactionEnvelopeFields, sig: string, envelope?: 'eip712' | 'eip191'): {
|
|
127
|
+
signer: string;
|
|
128
|
+
publicKeyHex: string;
|
|
129
|
+
signature: string;
|
|
130
|
+
};
|
|
131
|
+
//#endregion
|
|
132
|
+
export { ArcBlockTransactionEnvelopeFields, OcapGovernanceProposal, OcapGovernedAction, OcapMultiSigLockstep, OcapProposeOwner, OcapRollupPatch, OcapSignerRosterEntry, OcapSingleSignerMetadata, coerceOcapProposal, computeArcBlockTxEip191Digest, computeArcBlockTxEip712Digest, computeOcapProposalId, formatArcBlockTxEip191Text, membershipFromOcapProposal, parseOcapProposal, recoverArcBlockTxEnvelopeSigner, recoverOcapMembershipProposalSigner, serializeOcapProposal, validateOcapProposal };
|