@ocap/mcrypto 1.31.5 → 1.31.7

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.
@@ -84,5 +84,33 @@ type BridgeKeyPart = {
84
84
  * preimage. Returns a `0x` + 64 hex string (the evidence table key shape).
85
85
  */
86
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;
87
115
  //#endregion
88
- export { BRIDGE_GOV_DOMAIN_NAME, BRIDGE_GOV_DOMAIN_VERSION, BRIDGE_MEMBERSHIP_ACTION, BRIDGE_MEMBERSHIP_TYPE_STRING, BRIDGE_OWNER_ATTESTATION_TYPE_STRING, BridgeKeyPart, BridgeMembershipMessage, BridgeOwnerAttestationMessage, RecoveredBridgeSigner, bridgeEvidenceKey, computeBridgeEndpointsHash, computeBridgeMembershipDigest, computeBridgeOwnerAttestationDigest, ethAddressOfPublicKey, recoverBridgeSigner, signBridgeDigest, toHexDigest };
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 };
@@ -126,6 +126,50 @@ function bridgeEvidenceKey(prefix, parts) {
126
126
  });
127
127
  return `0x${bytesToHex(keccak_256(concat(...chunks)))}`;
128
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());
129
173
 
130
174
  //#endregion
131
- export { BRIDGE_GOV_DOMAIN_NAME, BRIDGE_GOV_DOMAIN_VERSION, BRIDGE_MEMBERSHIP_ACTION, BRIDGE_MEMBERSHIP_TYPE_STRING, BRIDGE_OWNER_ATTESTATION_TYPE_STRING, bridgeEvidenceKey, computeBridgeEndpointsHash, computeBridgeMembershipDigest, computeBridgeOwnerAttestationDigest, ethAddressOfPublicKey, recoverBridgeSigner, signBridgeDigest, toHexDigest };
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 };
@@ -2,7 +2,7 @@ import { BytesType } from "@ocap/util";
2
2
 
3
3
  //#region src/envelope.d.ts
4
4
  declare namespace envelope_d_exports {
5
- export { EIP712_BRIDGE_WITHDRAW_TYPE_STRING, ExpectedEnvelopeTxContext, WalletEnvelopeExtra, WalletEnvelopeType, assertEnvelopeMatchesTxContext, buildBridgeWithdrawEnvelopeExtra, buildEd25519EnvelopePayload, buildSolanaOffchainEnvelopeBytes, computeEip191EnvelopeDigest, computeEip712EnvelopeDigest, formatWalletEnvelopeText, isCanonicalWalletEnvelopeExtra, normalizeChallengeHex, parseWalletEnvelopeExtra, signEthereumEnvelope, verifyEthereumEnvelope };
5
+ export { EIP712_BRIDGE_WITHDRAW_TYPE_STRING, EIP712_ENVELOPE_DEFAULT_DOMAIN, ExpectedEnvelopeTxContext, WalletEnvelopeExtra, WalletEnvelopeType, assertEnvelopeMatchesTxContext, buildBridgeWithdrawEnvelopeExtra, buildEd25519EnvelopePayload, buildSolanaOffchainEnvelopeBytes, computeEip191EnvelopeDigest, computeEip712EnvelopeDigest, formatWalletEnvelopeText, isCanonicalWalletEnvelopeExtra, normalizeChallengeHex, parseWalletEnvelopeExtra, signEthereumEnvelope, verifyEthereumEnvelope };
6
6
  }
7
7
  type WalletEnvelopeType = 'eip191' | 'eip712' | 'solana-message' | 'solana-offchain';
8
8
  interface WalletEnvelopeExtra {
@@ -26,6 +26,15 @@ interface WalletEnvelopeExtra {
26
26
  token?: string;
27
27
  ethRecipient?: string;
28
28
  }
29
+ /**
30
+ * The EIP-712 domain `EIP712Domain(string name,string version)` used when the envelope leaves `domainName` /
31
+ * `domainVersion` out. It is the only domain an `ArcBridgeWithdraw` envelope may carry (#1715): the ERC-7730 descriptor
32
+ * a hardware wallet matches is registered for it, and any other domain would downgrade the signer to blind signing.
33
+ */
34
+ declare const EIP712_ENVELOPE_DEFAULT_DOMAIN: Readonly<{
35
+ name: "ArcBlock";
36
+ version: "1";
37
+ }>;
29
38
  /**
30
39
  * Normalize a challenge input (hex string or bytes) into a canonical lowercase `0x`-prefixed hex string.
31
40
  */
@@ -38,7 +47,8 @@ declare function isCanonicalWalletEnvelopeExtra(extra: unknown, keyType?: number
38
47
  /**
39
48
  * Build the `extra` object a wallet passes to `signEnvelope` for a bridge withdraw (#1465).
40
49
  * `bridge` is the OCAP bridge (rollup) address whose reserve is `itx.to`, `amount` the decimal base-unit string, `token` the bridge token address, `ethRecipient` the Ethereum recipient
41
- * exactly as written in `itx.data`.
50
+ * exactly as written in `itx.to`. The tx is a `withdraw_token_v2` (#1691): `bridge` is `itx.rollup`, `amount` is
51
+ * `itx.token.value` and `ethRecipient` is `itx.to`. `action` defaults to `withdraw_token_v2` and can be nothing else.
42
52
  */
43
53
  declare function buildBridgeWithdrawEnvelopeExtra(input: {
44
54
  envelope?: 'eip191' | 'eip712';
@@ -62,7 +72,8 @@ interface ExpectedEnvelopeTxContext {
62
72
  nonce?: string | number | bigint;
63
73
  action?: string;
64
74
  /**
65
- * Decoded bridge withdraw (transfer_v2 into the reserve), or null/undefined for any other tx.
75
+ * Decoded bridge withdraw (withdraw_token_v2 into a v2 bridge), or null/undefined
76
+ * for any other tx. A withdraw also requires `action` (the tx type) and an envelope naming exactly that type.
66
77
  * When set, the envelope MUST carry matching `amount`, `token` and `ethRecipient` (absent = rejected).
67
78
  * When not set, an envelope carrying any of those fields is rejected.
68
79
  */
@@ -113,4 +124,4 @@ declare function verifyEthereumEnvelope(challenge: BytesType, signature: BytesTy
113
124
  */
114
125
  declare function buildEd25519EnvelopePayload(challenge: BytesType, pk: BytesType, extra: string): Uint8Array;
115
126
  //#endregion
116
- export { EIP712_BRIDGE_WITHDRAW_TYPE_STRING, ExpectedEnvelopeTxContext, WalletEnvelopeExtra, WalletEnvelopeType, assertEnvelopeMatchesTxContext, buildBridgeWithdrawEnvelopeExtra, buildEd25519EnvelopePayload, buildSolanaOffchainEnvelopeBytes, computeEip191EnvelopeDigest, computeEip712EnvelopeDigest, envelope_d_exports, formatWalletEnvelopeText, isCanonicalWalletEnvelopeExtra, normalizeChallengeHex, parseWalletEnvelopeExtra, signEthereumEnvelope, verifyEthereumEnvelope };
127
+ export { EIP712_BRIDGE_WITHDRAW_TYPE_STRING, EIP712_ENVELOPE_DEFAULT_DOMAIN, ExpectedEnvelopeTxContext, WalletEnvelopeExtra, WalletEnvelopeType, assertEnvelopeMatchesTxContext, buildBridgeWithdrawEnvelopeExtra, buildEd25519EnvelopePayload, buildSolanaOffchainEnvelopeBytes, computeEip191EnvelopeDigest, computeEip712EnvelopeDigest, envelope_d_exports, formatWalletEnvelopeText, isCanonicalWalletEnvelopeExtra, normalizeChallengeHex, parseWalletEnvelopeExtra, signEthereumEnvelope, verifyEthereumEnvelope };
package/esm/envelope.mjs CHANGED
@@ -8,6 +8,7 @@ import { toHex, toUint8Array } from "@ocap/util";
8
8
  //#region src/envelope.ts
9
9
  var envelope_exports = /* @__PURE__ */ __exportAll({
10
10
  EIP712_BRIDGE_WITHDRAW_TYPE_STRING: () => EIP712_BRIDGE_WITHDRAW_TYPE_STRING,
11
+ EIP712_ENVELOPE_DEFAULT_DOMAIN: () => EIP712_ENVELOPE_DEFAULT_DOMAIN,
11
12
  assertEnvelopeMatchesTxContext: () => assertEnvelopeMatchesTxContext,
12
13
  buildBridgeWithdrawEnvelopeExtra: () => buildBridgeWithdrawEnvelopeExtra,
13
14
  buildEd25519EnvelopePayload: () => buildEd25519EnvelopePayload,
@@ -67,6 +68,15 @@ const SOLANA_OFFCHAIN_SIGNING_DOMAIN = new Uint8Array([
67
68
  110
68
69
  ]);
69
70
  const DEFAULT_SOLANA_APP_DOMAIN = "ArcBlock Transaction Envelope v1";
71
+ /**
72
+ * The EIP-712 domain `EIP712Domain(string name,string version)` used when the envelope leaves `domainName` /
73
+ * `domainVersion` out. It is the only domain an `ArcBridgeWithdraw` envelope may carry (#1715): the ERC-7730 descriptor
74
+ * a hardware wallet matches is registered for it, and any other domain would downgrade the signer to blind signing.
75
+ */
76
+ const EIP712_ENVELOPE_DEFAULT_DOMAIN = Object.freeze({
77
+ name: "ArcBlock",
78
+ version: "1"
79
+ });
70
80
  function isSafeSingleLine(value, maxLen = MAX_FIELD_LENGTH) {
71
81
  if (typeof value !== "string") return false;
72
82
  if (value.length > maxLen) return false;
@@ -125,6 +135,8 @@ const WITHDRAW_FIELDS = [
125
135
  "token",
126
136
  "ethRecipient"
127
137
  ];
138
+ /** The one tx type an `ArcBridgeWithdraw` envelope may name. */
139
+ const BRIDGE_WITHDRAW_ACTION = "withdraw_token_v2";
128
140
  const DECIMAL_AMOUNT = /^(0|[1-9][0-9]{0,77})$/;
129
141
  function hasAnyWithdrawField(meta) {
130
142
  return WITHDRAW_FIELDS.some((f) => meta[f] !== void 0);
@@ -135,13 +147,14 @@ function isWithdrawFieldSetValid(meta) {
135
147
  /**
136
148
  * Build the `extra` object a wallet passes to `signEnvelope` for a bridge withdraw (#1465).
137
149
  * `bridge` is the OCAP bridge (rollup) address whose reserve is `itx.to`, `amount` the decimal base-unit string, `token` the bridge token address, `ethRecipient` the Ethereum recipient
138
- * exactly as written in `itx.data`.
150
+ * exactly as written in `itx.to`. The tx is a `withdraw_token_v2` (#1691): `bridge` is `itx.rollup`, `amount` is
151
+ * `itx.token.value` and `ethRecipient` is `itx.to`. `action` defaults to `withdraw_token_v2` and can be nothing else.
139
152
  */
140
153
  function buildBridgeWithdrawEnvelopeExtra(input) {
141
154
  const extra = {
142
155
  envelope: input.envelope || "eip712",
143
156
  chainId: input.chainId,
144
- action: input.action || "transfer_v2",
157
+ action: input.action || BRIDGE_WITHDRAW_ACTION,
145
158
  from: input.from,
146
159
  nonce: String(input.nonce),
147
160
  bridge: input.bridge,
@@ -170,12 +183,17 @@ function assertEnvelopeMatchesTxContext(extra, expected) {
170
183
  if (withdraw) {
171
184
  if (!hasAnyWithdrawField(parsed) || !isWithdrawFieldSetValid(parsed)) throw new Error("Bridge withdraw requires an envelope carrying bridge, amount, token and ethRecipient");
172
185
  if (!ETHEREUM_ENVELOPES.has(parsed.envelope)) throw new Error("Bridge withdraw requires an Ethereum envelope");
186
+ if (parsed.domainName !== void 0 && parsed.domainName !== EIP712_ENVELOPE_DEFAULT_DOMAIN.name || parsed.domainVersion !== void 0 && parsed.domainVersion !== EIP712_ENVELOPE_DEFAULT_DOMAIN.version) throw new Error(`Bridge withdraw envelope domain must be ${EIP712_ENVELOPE_DEFAULT_DOMAIN.name} / ${EIP712_ENVELOPE_DEFAULT_DOMAIN.version}`);
173
187
  for (const field of [
174
188
  "chainId",
175
189
  "from",
176
190
  "nonce"
177
191
  ]) if (parsed[field] === void 0 || parsed[field] === "") throw new Error(`Bridge withdraw envelope is missing "${field}"`);
178
- if (parsed.action !== "transfer_v2" && parsed.action !== "fg:t:transfer_v2") throw new Error(`Bridge withdraw envelope action must be transfer_v2, got "${parsed.action ?? ""}"`);
192
+ const action = typeof parsed.action === "string" ? parsed.action.replace(/^fg:t:/, "") : "";
193
+ if (action !== BRIDGE_WITHDRAW_ACTION) throw new Error(`Bridge withdraw envelope action must be ${BRIDGE_WITHDRAW_ACTION}, got "${parsed.action ?? ""}"`);
194
+ const expectedAction = typeof expected.action === "string" ? expected.action.replace(/^fg:t:/, "") : "";
195
+ if (!expectedAction) throw new Error("Bridge withdraw envelope can not be checked without the transaction action");
196
+ if (action !== expectedAction) throw new Error(`Envelope action "${parsed.action}" does not match transaction action "${expected.action}"`);
179
197
  if (parsed.bridge !== withdraw.bridge) throw new Error(`Envelope bridge "${parsed.bridge}" does not match transaction bridge "${withdraw.bridge}"`);
180
198
  if (parsed.amount !== withdraw.amount) throw new Error(`Envelope amount "${parsed.amount}" does not match transaction amount "${withdraw.amount}"`);
181
199
  if (parsed.token !== withdraw.token) throw new Error(`Envelope token "${parsed.token}" does not match transaction token "${withdraw.token}"`);
@@ -261,8 +279,8 @@ function computeEip712EnvelopeDigest(challenge, meta = {}) {
261
279
  ...WITHDRAW_FIELDS
262
280
  ];
263
281
  for (const field of fields) if (meta[field] !== void 0 && !isSafeSingleLine(meta[field])) throw new Error(`Invalid character in wallet envelope field "${field}"`);
264
- const domainName = meta.domainName || "ArcBlock";
265
- const domainVersion = meta.domainVersion || "1";
282
+ const domainName = meta.domainName || EIP712_ENVELOPE_DEFAULT_DOMAIN.name;
283
+ const domainVersion = meta.domainVersion || EIP712_ENVELOPE_DEFAULT_DOMAIN.version;
266
284
  const chainId = meta.chainId || "arcblock";
267
285
  const action = meta.action || "transaction";
268
286
  const from = meta.from || "";
@@ -399,4 +417,4 @@ function buildEd25519EnvelopePayload(challenge, pk, extra) {
399
417
  }
400
418
 
401
419
  //#endregion
402
- export { EIP712_BRIDGE_WITHDRAW_TYPE_STRING, assertEnvelopeMatchesTxContext, buildBridgeWithdrawEnvelopeExtra, buildEd25519EnvelopePayload, buildSolanaOffchainEnvelopeBytes, computeEip191EnvelopeDigest, computeEip712EnvelopeDigest, envelope_exports, formatWalletEnvelopeText, isCanonicalWalletEnvelopeExtra, normalizeChallengeHex, parseWalletEnvelopeExtra, signEthereumEnvelope, verifyEthereumEnvelope };
420
+ export { EIP712_BRIDGE_WITHDRAW_TYPE_STRING, EIP712_ENVELOPE_DEFAULT_DOMAIN, assertEnvelopeMatchesTxContext, buildBridgeWithdrawEnvelopeExtra, buildEd25519EnvelopePayload, buildSolanaOffchainEnvelopeBytes, computeEip191EnvelopeDigest, computeEip712EnvelopeDigest, envelope_exports, formatWalletEnvelopeText, isCanonicalWalletEnvelopeExtra, normalizeChallengeHex, parseWalletEnvelopeExtra, signEthereumEnvelope, verifyEthereumEnvelope };
package/esm/index.d.mts CHANGED
@@ -1,5 +1,5 @@
1
- import { BRIDGE_GOV_DOMAIN_NAME, BRIDGE_GOV_DOMAIN_VERSION, BRIDGE_MEMBERSHIP_ACTION, BRIDGE_MEMBERSHIP_TYPE_STRING, BRIDGE_OWNER_ATTESTATION_TYPE_STRING, BridgeKeyPart, BridgeMembershipMessage, BridgeOwnerAttestationMessage, RecoveredBridgeSigner, bridgeEvidenceKey, computeBridgeEndpointsHash, computeBridgeMembershipDigest, computeBridgeOwnerAttestationDigest, ethAddressOfPublicKey, recoverBridgeSigner, signBridgeDigest, toHexDigest } from "./bridge-governance.mjs";
2
- import { EIP712_BRIDGE_WITHDRAW_TYPE_STRING, ExpectedEnvelopeTxContext, WalletEnvelopeExtra, WalletEnvelopeType, assertEnvelopeMatchesTxContext, buildBridgeWithdrawEnvelopeExtra, buildEd25519EnvelopePayload, buildSolanaOffchainEnvelopeBytes, computeEip191EnvelopeDigest, computeEip712EnvelopeDigest, envelope_d_exports, formatWalletEnvelopeText, isCanonicalWalletEnvelopeExtra, normalizeChallengeHex, parseWalletEnvelopeExtra, signEthereumEnvelope, verifyEthereumEnvelope } from "./envelope.mjs";
1
+ import { 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 } from "./bridge-governance.mjs";
2
+ import { EIP712_BRIDGE_WITHDRAW_TYPE_STRING, EIP712_ENVELOPE_DEFAULT_DOMAIN, ExpectedEnvelopeTxContext, WalletEnvelopeExtra, WalletEnvelopeType, assertEnvelopeMatchesTxContext, buildBridgeWithdrawEnvelopeExtra, buildEd25519EnvelopePayload, buildSolanaOffchainEnvelopeBytes, computeEip191EnvelopeDigest, computeEip712EnvelopeDigest, envelope_d_exports, formatWalletEnvelopeText, isCanonicalWalletEnvelopeExtra, normalizeChallengeHex, parseWalletEnvelopeExtra, signEthereumEnvelope, verifyEthereumEnvelope } from "./envelope.mjs";
3
3
  import { StrictEthAddressFailure, StrictEthAddressResult, isStrictEthAddress, parseStrictEthAddress } from "./eth-address.mjs";
4
4
  import { KeccakHasher } from "./hasher/keccak.mjs";
5
5
  import { Sha2Hasher, hmacSha256 } from "./hasher/sha2.mjs";
@@ -243,4 +243,4 @@ declare function getRandomBytes(length: number, encoding?: 'Uint8Array'): Uint8A
243
243
  declare function getRandomBytes(length: number, encoding?: EncodingType): BytesType;
244
244
  declare const toTxHash: (buf: Buffer | Uint8Array) => string;
245
245
  //#endregion
246
- export { AddressType, BRIDGE_GOV_DOMAIN_NAME, BRIDGE_GOV_DOMAIN_VERSION, BRIDGE_MEMBERSHIP_ACTION, BRIDGE_MEMBERSHIP_TYPE_STRING, BRIDGE_OWNER_ATTESTATION_TYPE_STRING, BridgeKeyPart, BridgeMembershipMessage, BridgeOwnerAttestationMessage, EIP712_BRIDGE_WITHDRAW_TYPE_STRING, ExpectedEnvelopeTxContext, HashFnType, HashType, Hasher, KeyType, RecoveredBridgeSigner, RoleType, Signer, SignerType, StrictEthAddressFailure, StrictEthAddressResult, WalletEnvelopeExtra, WalletEnvelopeType, assertEnvelopeMatchesTxContext, bridgeEvidenceKey, buildBridgeWithdrawEnvelopeExtra, buildEd25519EnvelopePayload, buildSolanaOffchainEnvelopeBytes, computeBridgeEndpointsHash, computeBridgeMembershipDigest, computeBridgeOwnerAttestationDigest, computeEip191EnvelopeDigest, computeEip712EnvelopeDigest, envelope_d_exports as envelope, ethAddressOfPublicKey, formatWalletEnvelopeText, getHasher, getRandomBytes, getSigner, hmacSha256, isCanonicalWalletEnvelopeExtra, isStrictEthAddress, normalizeChallengeHex, parseStrictEthAddress, parseWalletEnvelopeExtra, recoverBridgeSigner, signBridgeDigest, signEthereumEnvelope, toHexDigest, toTxHash, types, verifyEthereumEnvelope, webauthn_d_exports as webauthn };
246
+ export { AddressType, 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, EIP712_BRIDGE_WITHDRAW_TYPE_STRING, EIP712_ENVELOPE_DEFAULT_DOMAIN, ExpectedEnvelopeTxContext, HashFnType, HashType, Hasher, KeyType, RecoveredBridgeSigner, RoleType, Signer, SignerType, StrictEthAddressFailure, StrictEthAddressResult, WalletEnvelopeExtra, WalletEnvelopeType, assertEnvelopeMatchesTxContext, bridgeEvidenceKey, bridgeReleaseBucketKey, bridgeReleaseTombstoneKey, buildBridgeWithdrawEnvelopeExtra, buildEd25519EnvelopePayload, buildSolanaOffchainEnvelopeBytes, computeBridgeEndpointsHash, computeBridgeMembershipDigest, computeBridgeOwnerAttestationDigest, computeEip191EnvelopeDigest, computeEip712EnvelopeDigest, envelope_d_exports as envelope, ethAddressOfPublicKey, formatWalletEnvelopeText, getHasher, getRandomBytes, getSigner, hmacSha256, inBridgeReleaseKeySpace, isBridgeReleaseKey, isCanonicalWalletEnvelopeExtra, isStrictEthAddress, normalizeChallengeHex, parseStrictEthAddress, parseWalletEnvelopeExtra, recoverBridgeSigner, signBridgeDigest, signEthereumEnvelope, toHexDigest, toTxHash, types, verifyEthereumEnvelope, webauthn_d_exports as webauthn };
package/esm/index.mjs CHANGED
@@ -1,7 +1,7 @@
1
- import { BRIDGE_GOV_DOMAIN_NAME, BRIDGE_GOV_DOMAIN_VERSION, BRIDGE_MEMBERSHIP_ACTION, BRIDGE_MEMBERSHIP_TYPE_STRING, BRIDGE_OWNER_ATTESTATION_TYPE_STRING, bridgeEvidenceKey, computeBridgeEndpointsHash, computeBridgeMembershipDigest, computeBridgeOwnerAttestationDigest, ethAddressOfPublicKey, recoverBridgeSigner, signBridgeDigest, toHexDigest } from "./bridge-governance.mjs";
1
+ import { 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 } from "./bridge-governance.mjs";
2
2
  import { encode } from "./encode.mjs";
3
3
  import { isStrictEthAddress, parseStrictEthAddress } from "./eth-address.mjs";
4
- import { EIP712_BRIDGE_WITHDRAW_TYPE_STRING, assertEnvelopeMatchesTxContext, buildBridgeWithdrawEnvelopeExtra, buildEd25519EnvelopePayload, buildSolanaOffchainEnvelopeBytes, computeEip191EnvelopeDigest, computeEip712EnvelopeDigest, envelope_exports, formatWalletEnvelopeText, isCanonicalWalletEnvelopeExtra, normalizeChallengeHex, parseWalletEnvelopeExtra, signEthereumEnvelope, verifyEthereumEnvelope } from "./envelope.mjs";
4
+ import { EIP712_BRIDGE_WITHDRAW_TYPE_STRING, EIP712_ENVELOPE_DEFAULT_DOMAIN, assertEnvelopeMatchesTxContext, buildBridgeWithdrawEnvelopeExtra, buildEd25519EnvelopePayload, buildSolanaOffchainEnvelopeBytes, computeEip191EnvelopeDigest, computeEip712EnvelopeDigest, envelope_exports, formatWalletEnvelopeText, isCanonicalWalletEnvelopeExtra, normalizeChallengeHex, parseWalletEnvelopeExtra, signEthereumEnvelope, verifyEthereumEnvelope } from "./envelope.mjs";
5
5
  import keccak_default from "./hasher/keccak.mjs";
6
6
  import sha2_default, { hmacSha256 } from "./hasher/sha2.mjs";
7
7
  import sha3_default from "./hasher/sha3.mjs";
@@ -186,4 +186,4 @@ function getRandomBytes(length = 32, encoding = "hex") {
186
186
  const toTxHash = (buf) => Hasher.SHA2.hash256(buf, 1, "hex").replace(/^0x/, "").toUpperCase();
187
187
 
188
188
  //#endregion
189
- export { BRIDGE_GOV_DOMAIN_NAME, BRIDGE_GOV_DOMAIN_VERSION, BRIDGE_MEMBERSHIP_ACTION, BRIDGE_MEMBERSHIP_TYPE_STRING, BRIDGE_OWNER_ATTESTATION_TYPE_STRING, EIP712_BRIDGE_WITHDRAW_TYPE_STRING, Hasher, Signer, assertEnvelopeMatchesTxContext, bridgeEvidenceKey, buildBridgeWithdrawEnvelopeExtra, buildEd25519EnvelopePayload, buildSolanaOffchainEnvelopeBytes, computeBridgeEndpointsHash, computeBridgeMembershipDigest, computeBridgeOwnerAttestationDigest, computeEip191EnvelopeDigest, computeEip712EnvelopeDigest, envelope_exports as envelope, ethAddressOfPublicKey, formatWalletEnvelopeText, getHasher, getRandomBytes, getSigner, hmacSha256, isCanonicalWalletEnvelopeExtra, isStrictEthAddress, normalizeChallengeHex, parseStrictEthAddress, parseWalletEnvelopeExtra, recoverBridgeSigner, signBridgeDigest, signEthereumEnvelope, toHexDigest, toTxHash, types, verifyEthereumEnvelope, webauthn_exports as webauthn };
189
+ 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, EIP712_BRIDGE_WITHDRAW_TYPE_STRING, EIP712_ENVELOPE_DEFAULT_DOMAIN, Hasher, Signer, assertEnvelopeMatchesTxContext, bridgeEvidenceKey, bridgeReleaseBucketKey, bridgeReleaseTombstoneKey, buildBridgeWithdrawEnvelopeExtra, buildEd25519EnvelopePayload, buildSolanaOffchainEnvelopeBytes, computeBridgeEndpointsHash, computeBridgeMembershipDigest, computeBridgeOwnerAttestationDigest, computeEip191EnvelopeDigest, computeEip712EnvelopeDigest, envelope_exports as envelope, ethAddressOfPublicKey, formatWalletEnvelopeText, getHasher, getRandomBytes, getSigner, hmacSha256, inBridgeReleaseKeySpace, isBridgeReleaseKey, isCanonicalWalletEnvelopeExtra, isStrictEthAddress, normalizeChallengeHex, parseStrictEthAddress, parseWalletEnvelopeExtra, recoverBridgeSigner, signBridgeDigest, signEthereumEnvelope, toHexDigest, toTxHash, types, verifyEthereumEnvelope, webauthn_exports as webauthn };
@@ -127,6 +127,50 @@ function bridgeEvidenceKey(prefix, parts) {
127
127
  });
128
128
  return `0x${require_utils.bytesToHex(require_sha3.keccak_256(concat(...chunks)))}`;
129
129
  }
130
+ /**
131
+ * 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
132
+ * first 63 hex digits of the keccak digest of the `bridgeEvidenceKey` preimage, 66 characters in total.
133
+ *
134
+ * Legacy rollup v1 protocols store evidence rows at a caller-chosen key validated only by `patterns.txHash`
135
+ * (`^(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
136
+ * carry ever lands in this key space, and the gate can tell a release row by its key alone. 66 characters is exactly the
137
+ * width of a `0x` + 64 hex key, so every statedb backend that stores today's evidence keys stores these. The `:` also
138
+ * keeps the key from ever parsing as a DID (base58 has no `:`). 252 bits of keccak keep collision resistance at 2^126.
139
+ */
140
+ const BRIDGE_RELEASE_TOMBSTONE_TAG = "rt:";
141
+ const BRIDGE_RELEASE_BUCKET_TAG = "rb:";
142
+ const RELEASE_TOMBSTONE_DOMAIN = "arc-bridge:release:";
143
+ const RELEASE_BUCKET_DOMAIN = "arc-bridge:release-bucket:";
144
+ /** a canonical release key: tag + 63 lowercase hex */
145
+ const BRIDGE_RELEASE_KEY_PATTERN = /^r[tb]:[0-9a-f]{63}$/;
146
+ const releaseKey = (tag, domain, parts) => `${tag}${bridgeEvidenceKey(domain, parts).slice(2, 65)}`;
147
+ /**
148
+ * Tombstone key of a release: `rt:` + keccak256("arc-bridge:release:" || uint kind || bytes32 evidence || uint ordinal ||
149
+ * bridge). `evidence` is a `0x` bytes32 (lowercased here); `bridge` the canonical bridge address.
150
+ */
151
+ function bridgeReleaseTombstoneKey(bridge, kind, evidence, ordinal) {
152
+ return releaseKey(BRIDGE_RELEASE_TOMBSTONE_TAG, RELEASE_TOMBSTONE_DOMAIN, [
153
+ { uint: kind },
154
+ { bytes32: String(evidence).toLowerCase() },
155
+ { uint: ordinal },
156
+ { text: bridge }
157
+ ]);
158
+ }
159
+ /** Key of slot `slot` of ring `ring` (0 = deposit, 1 = refund) of `bridge`: `rb:` + keccak256("arc-bridge:release-bucket:" || uint ring || uint slot || bridge). */
160
+ function bridgeReleaseBucketKey(bridge, ring, slot) {
161
+ return releaseKey(BRIDGE_RELEASE_BUCKET_TAG, RELEASE_BUCKET_DOMAIN, [
162
+ { uint: ring },
163
+ { uint: slot },
164
+ { text: bridge }
165
+ ]);
166
+ }
167
+ /** Whether `key` is a canonical release key (tombstone or bucket). */
168
+ const isBridgeReleaseKey = (key) => typeof key === "string" && BRIDGE_RELEASE_KEY_PATTERN.test(key);
169
+ /**
170
+ * Whether `key` is in the release key space in ANY spelling (case, surrounding whitespace): what the gate refuses to any
171
+ * tx type but a bridge release.
172
+ */
173
+ const inBridgeReleaseKeySpace = (key) => typeof key === "string" && /^r[tb]:/i.test(key.trim());
130
174
 
131
175
  //#endregion
132
176
  exports.BRIDGE_GOV_DOMAIN_NAME = BRIDGE_GOV_DOMAIN_NAME;
@@ -134,11 +178,18 @@ exports.BRIDGE_GOV_DOMAIN_VERSION = BRIDGE_GOV_DOMAIN_VERSION;
134
178
  exports.BRIDGE_MEMBERSHIP_ACTION = BRIDGE_MEMBERSHIP_ACTION;
135
179
  exports.BRIDGE_MEMBERSHIP_TYPE_STRING = BRIDGE_MEMBERSHIP_TYPE_STRING;
136
180
  exports.BRIDGE_OWNER_ATTESTATION_TYPE_STRING = BRIDGE_OWNER_ATTESTATION_TYPE_STRING;
181
+ exports.BRIDGE_RELEASE_BUCKET_TAG = BRIDGE_RELEASE_BUCKET_TAG;
182
+ exports.BRIDGE_RELEASE_KEY_PATTERN = BRIDGE_RELEASE_KEY_PATTERN;
183
+ exports.BRIDGE_RELEASE_TOMBSTONE_TAG = BRIDGE_RELEASE_TOMBSTONE_TAG;
137
184
  exports.bridgeEvidenceKey = bridgeEvidenceKey;
185
+ exports.bridgeReleaseBucketKey = bridgeReleaseBucketKey;
186
+ exports.bridgeReleaseTombstoneKey = bridgeReleaseTombstoneKey;
138
187
  exports.computeBridgeEndpointsHash = computeBridgeEndpointsHash;
139
188
  exports.computeBridgeMembershipDigest = computeBridgeMembershipDigest;
140
189
  exports.computeBridgeOwnerAttestationDigest = computeBridgeOwnerAttestationDigest;
141
190
  exports.ethAddressOfPublicKey = ethAddressOfPublicKey;
191
+ exports.inBridgeReleaseKeySpace = inBridgeReleaseKeySpace;
192
+ exports.isBridgeReleaseKey = isBridgeReleaseKey;
142
193
  exports.recoverBridgeSigner = recoverBridgeSigner;
143
194
  exports.signBridgeDigest = signBridgeDigest;
144
195
  exports.toHexDigest = toHexDigest;
@@ -84,5 +84,33 @@ type BridgeKeyPart = {
84
84
  * preimage. Returns a `0x` + 64 hex string (the evidence table key shape).
85
85
  */
86
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;
87
115
  //#endregion
88
- export { BRIDGE_GOV_DOMAIN_NAME, BRIDGE_GOV_DOMAIN_VERSION, BRIDGE_MEMBERSHIP_ACTION, BRIDGE_MEMBERSHIP_TYPE_STRING, BRIDGE_OWNER_ATTESTATION_TYPE_STRING, BridgeKeyPart, BridgeMembershipMessage, BridgeOwnerAttestationMessage, RecoveredBridgeSigner, bridgeEvidenceKey, computeBridgeEndpointsHash, computeBridgeMembershipDigest, computeBridgeOwnerAttestationDigest, ethAddressOfPublicKey, recoverBridgeSigner, signBridgeDigest, toHexDigest };
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 };
package/lib/envelope.cjs CHANGED
@@ -8,6 +8,7 @@ let _ocap_util = require("@ocap/util");
8
8
  //#region src/envelope.ts
9
9
  var envelope_exports = /* @__PURE__ */ require_rolldown_runtime.__exportAll({
10
10
  EIP712_BRIDGE_WITHDRAW_TYPE_STRING: () => EIP712_BRIDGE_WITHDRAW_TYPE_STRING,
11
+ EIP712_ENVELOPE_DEFAULT_DOMAIN: () => EIP712_ENVELOPE_DEFAULT_DOMAIN,
11
12
  assertEnvelopeMatchesTxContext: () => assertEnvelopeMatchesTxContext,
12
13
  buildBridgeWithdrawEnvelopeExtra: () => buildBridgeWithdrawEnvelopeExtra,
13
14
  buildEd25519EnvelopePayload: () => buildEd25519EnvelopePayload,
@@ -67,6 +68,15 @@ const SOLANA_OFFCHAIN_SIGNING_DOMAIN = new Uint8Array([
67
68
  110
68
69
  ]);
69
70
  const DEFAULT_SOLANA_APP_DOMAIN = "ArcBlock Transaction Envelope v1";
71
+ /**
72
+ * The EIP-712 domain `EIP712Domain(string name,string version)` used when the envelope leaves `domainName` /
73
+ * `domainVersion` out. It is the only domain an `ArcBridgeWithdraw` envelope may carry (#1715): the ERC-7730 descriptor
74
+ * a hardware wallet matches is registered for it, and any other domain would downgrade the signer to blind signing.
75
+ */
76
+ const EIP712_ENVELOPE_DEFAULT_DOMAIN = Object.freeze({
77
+ name: "ArcBlock",
78
+ version: "1"
79
+ });
70
80
  function isSafeSingleLine(value, maxLen = MAX_FIELD_LENGTH) {
71
81
  if (typeof value !== "string") return false;
72
82
  if (value.length > maxLen) return false;
@@ -125,6 +135,8 @@ const WITHDRAW_FIELDS = [
125
135
  "token",
126
136
  "ethRecipient"
127
137
  ];
138
+ /** The one tx type an `ArcBridgeWithdraw` envelope may name. */
139
+ const BRIDGE_WITHDRAW_ACTION = "withdraw_token_v2";
128
140
  const DECIMAL_AMOUNT = /^(0|[1-9][0-9]{0,77})$/;
129
141
  function hasAnyWithdrawField(meta) {
130
142
  return WITHDRAW_FIELDS.some((f) => meta[f] !== void 0);
@@ -135,13 +147,14 @@ function isWithdrawFieldSetValid(meta) {
135
147
  /**
136
148
  * Build the `extra` object a wallet passes to `signEnvelope` for a bridge withdraw (#1465).
137
149
  * `bridge` is the OCAP bridge (rollup) address whose reserve is `itx.to`, `amount` the decimal base-unit string, `token` the bridge token address, `ethRecipient` the Ethereum recipient
138
- * exactly as written in `itx.data`.
150
+ * exactly as written in `itx.to`. The tx is a `withdraw_token_v2` (#1691): `bridge` is `itx.rollup`, `amount` is
151
+ * `itx.token.value` and `ethRecipient` is `itx.to`. `action` defaults to `withdraw_token_v2` and can be nothing else.
139
152
  */
140
153
  function buildBridgeWithdrawEnvelopeExtra(input) {
141
154
  const extra = {
142
155
  envelope: input.envelope || "eip712",
143
156
  chainId: input.chainId,
144
- action: input.action || "transfer_v2",
157
+ action: input.action || BRIDGE_WITHDRAW_ACTION,
145
158
  from: input.from,
146
159
  nonce: String(input.nonce),
147
160
  bridge: input.bridge,
@@ -170,12 +183,17 @@ function assertEnvelopeMatchesTxContext(extra, expected) {
170
183
  if (withdraw) {
171
184
  if (!hasAnyWithdrawField(parsed) || !isWithdrawFieldSetValid(parsed)) throw new Error("Bridge withdraw requires an envelope carrying bridge, amount, token and ethRecipient");
172
185
  if (!ETHEREUM_ENVELOPES.has(parsed.envelope)) throw new Error("Bridge withdraw requires an Ethereum envelope");
186
+ if (parsed.domainName !== void 0 && parsed.domainName !== EIP712_ENVELOPE_DEFAULT_DOMAIN.name || parsed.domainVersion !== void 0 && parsed.domainVersion !== EIP712_ENVELOPE_DEFAULT_DOMAIN.version) throw new Error(`Bridge withdraw envelope domain must be ${EIP712_ENVELOPE_DEFAULT_DOMAIN.name} / ${EIP712_ENVELOPE_DEFAULT_DOMAIN.version}`);
173
187
  for (const field of [
174
188
  "chainId",
175
189
  "from",
176
190
  "nonce"
177
191
  ]) if (parsed[field] === void 0 || parsed[field] === "") throw new Error(`Bridge withdraw envelope is missing "${field}"`);
178
- if (parsed.action !== "transfer_v2" && parsed.action !== "fg:t:transfer_v2") throw new Error(`Bridge withdraw envelope action must be transfer_v2, got "${parsed.action ?? ""}"`);
192
+ const action = typeof parsed.action === "string" ? parsed.action.replace(/^fg:t:/, "") : "";
193
+ if (action !== BRIDGE_WITHDRAW_ACTION) throw new Error(`Bridge withdraw envelope action must be ${BRIDGE_WITHDRAW_ACTION}, got "${parsed.action ?? ""}"`);
194
+ const expectedAction = typeof expected.action === "string" ? expected.action.replace(/^fg:t:/, "") : "";
195
+ if (!expectedAction) throw new Error("Bridge withdraw envelope can not be checked without the transaction action");
196
+ if (action !== expectedAction) throw new Error(`Envelope action "${parsed.action}" does not match transaction action "${expected.action}"`);
179
197
  if (parsed.bridge !== withdraw.bridge) throw new Error(`Envelope bridge "${parsed.bridge}" does not match transaction bridge "${withdraw.bridge}"`);
180
198
  if (parsed.amount !== withdraw.amount) throw new Error(`Envelope amount "${parsed.amount}" does not match transaction amount "${withdraw.amount}"`);
181
199
  if (parsed.token !== withdraw.token) throw new Error(`Envelope token "${parsed.token}" does not match transaction token "${withdraw.token}"`);
@@ -261,8 +279,8 @@ function computeEip712EnvelopeDigest(challenge, meta = {}) {
261
279
  ...WITHDRAW_FIELDS
262
280
  ];
263
281
  for (const field of fields) if (meta[field] !== void 0 && !isSafeSingleLine(meta[field])) throw new Error(`Invalid character in wallet envelope field "${field}"`);
264
- const domainName = meta.domainName || "ArcBlock";
265
- const domainVersion = meta.domainVersion || "1";
282
+ const domainName = meta.domainName || EIP712_ENVELOPE_DEFAULT_DOMAIN.name;
283
+ const domainVersion = meta.domainVersion || EIP712_ENVELOPE_DEFAULT_DOMAIN.version;
266
284
  const chainId = meta.chainId || "arcblock";
267
285
  const action = meta.action || "transaction";
268
286
  const from = meta.from || "";
@@ -400,6 +418,7 @@ function buildEd25519EnvelopePayload(challenge, pk, extra) {
400
418
 
401
419
  //#endregion
402
420
  exports.EIP712_BRIDGE_WITHDRAW_TYPE_STRING = EIP712_BRIDGE_WITHDRAW_TYPE_STRING;
421
+ exports.EIP712_ENVELOPE_DEFAULT_DOMAIN = EIP712_ENVELOPE_DEFAULT_DOMAIN;
403
422
  exports.assertEnvelopeMatchesTxContext = assertEnvelopeMatchesTxContext;
404
423
  exports.buildBridgeWithdrawEnvelopeExtra = buildBridgeWithdrawEnvelopeExtra;
405
424
  exports.buildEd25519EnvelopePayload = buildEd25519EnvelopePayload;
@@ -2,7 +2,7 @@ import { BytesType } from "@ocap/util";
2
2
 
3
3
  //#region src/envelope.d.ts
4
4
  declare namespace envelope_d_exports {
5
- export { EIP712_BRIDGE_WITHDRAW_TYPE_STRING, ExpectedEnvelopeTxContext, WalletEnvelopeExtra, WalletEnvelopeType, assertEnvelopeMatchesTxContext, buildBridgeWithdrawEnvelopeExtra, buildEd25519EnvelopePayload, buildSolanaOffchainEnvelopeBytes, computeEip191EnvelopeDigest, computeEip712EnvelopeDigest, formatWalletEnvelopeText, isCanonicalWalletEnvelopeExtra, normalizeChallengeHex, parseWalletEnvelopeExtra, signEthereumEnvelope, verifyEthereumEnvelope };
5
+ export { EIP712_BRIDGE_WITHDRAW_TYPE_STRING, EIP712_ENVELOPE_DEFAULT_DOMAIN, ExpectedEnvelopeTxContext, WalletEnvelopeExtra, WalletEnvelopeType, assertEnvelopeMatchesTxContext, buildBridgeWithdrawEnvelopeExtra, buildEd25519EnvelopePayload, buildSolanaOffchainEnvelopeBytes, computeEip191EnvelopeDigest, computeEip712EnvelopeDigest, formatWalletEnvelopeText, isCanonicalWalletEnvelopeExtra, normalizeChallengeHex, parseWalletEnvelopeExtra, signEthereumEnvelope, verifyEthereumEnvelope };
6
6
  }
7
7
  type WalletEnvelopeType = 'eip191' | 'eip712' | 'solana-message' | 'solana-offchain';
8
8
  interface WalletEnvelopeExtra {
@@ -26,6 +26,15 @@ interface WalletEnvelopeExtra {
26
26
  token?: string;
27
27
  ethRecipient?: string;
28
28
  }
29
+ /**
30
+ * The EIP-712 domain `EIP712Domain(string name,string version)` used when the envelope leaves `domainName` /
31
+ * `domainVersion` out. It is the only domain an `ArcBridgeWithdraw` envelope may carry (#1715): the ERC-7730 descriptor
32
+ * a hardware wallet matches is registered for it, and any other domain would downgrade the signer to blind signing.
33
+ */
34
+ declare const EIP712_ENVELOPE_DEFAULT_DOMAIN: Readonly<{
35
+ name: "ArcBlock";
36
+ version: "1";
37
+ }>;
29
38
  /**
30
39
  * Normalize a challenge input (hex string or bytes) into a canonical lowercase `0x`-prefixed hex string.
31
40
  */
@@ -38,7 +47,8 @@ declare function isCanonicalWalletEnvelopeExtra(extra: unknown, keyType?: number
38
47
  /**
39
48
  * Build the `extra` object a wallet passes to `signEnvelope` for a bridge withdraw (#1465).
40
49
  * `bridge` is the OCAP bridge (rollup) address whose reserve is `itx.to`, `amount` the decimal base-unit string, `token` the bridge token address, `ethRecipient` the Ethereum recipient
41
- * exactly as written in `itx.data`.
50
+ * exactly as written in `itx.to`. The tx is a `withdraw_token_v2` (#1691): `bridge` is `itx.rollup`, `amount` is
51
+ * `itx.token.value` and `ethRecipient` is `itx.to`. `action` defaults to `withdraw_token_v2` and can be nothing else.
42
52
  */
43
53
  declare function buildBridgeWithdrawEnvelopeExtra(input: {
44
54
  envelope?: 'eip191' | 'eip712';
@@ -62,7 +72,8 @@ interface ExpectedEnvelopeTxContext {
62
72
  nonce?: string | number | bigint;
63
73
  action?: string;
64
74
  /**
65
- * Decoded bridge withdraw (transfer_v2 into the reserve), or null/undefined for any other tx.
75
+ * Decoded bridge withdraw (withdraw_token_v2 into a v2 bridge), or null/undefined
76
+ * for any other tx. A withdraw also requires `action` (the tx type) and an envelope naming exactly that type.
66
77
  * When set, the envelope MUST carry matching `amount`, `token` and `ethRecipient` (absent = rejected).
67
78
  * When not set, an envelope carrying any of those fields is rejected.
68
79
  */
@@ -113,4 +124,4 @@ declare function verifyEthereumEnvelope(challenge: BytesType, signature: BytesTy
113
124
  */
114
125
  declare function buildEd25519EnvelopePayload(challenge: BytesType, pk: BytesType, extra: string): Uint8Array;
115
126
  //#endregion
116
- export { EIP712_BRIDGE_WITHDRAW_TYPE_STRING, ExpectedEnvelopeTxContext, WalletEnvelopeExtra, WalletEnvelopeType, assertEnvelopeMatchesTxContext, buildBridgeWithdrawEnvelopeExtra, buildEd25519EnvelopePayload, buildSolanaOffchainEnvelopeBytes, computeEip191EnvelopeDigest, computeEip712EnvelopeDigest, envelope_d_exports, formatWalletEnvelopeText, isCanonicalWalletEnvelopeExtra, normalizeChallengeHex, parseWalletEnvelopeExtra, signEthereumEnvelope, verifyEthereumEnvelope };
127
+ export { EIP712_BRIDGE_WITHDRAW_TYPE_STRING, EIP712_ENVELOPE_DEFAULT_DOMAIN, ExpectedEnvelopeTxContext, WalletEnvelopeExtra, WalletEnvelopeType, assertEnvelopeMatchesTxContext, buildBridgeWithdrawEnvelopeExtra, buildEd25519EnvelopePayload, buildSolanaOffchainEnvelopeBytes, computeEip191EnvelopeDigest, computeEip712EnvelopeDigest, envelope_d_exports, formatWalletEnvelopeText, isCanonicalWalletEnvelopeExtra, normalizeChallengeHex, parseWalletEnvelopeExtra, signEthereumEnvelope, verifyEthereumEnvelope };
package/lib/index.cjs CHANGED
@@ -193,11 +193,17 @@ exports.BRIDGE_GOV_DOMAIN_VERSION = require_bridge_governance.BRIDGE_GOV_DOMAIN_
193
193
  exports.BRIDGE_MEMBERSHIP_ACTION = require_bridge_governance.BRIDGE_MEMBERSHIP_ACTION;
194
194
  exports.BRIDGE_MEMBERSHIP_TYPE_STRING = require_bridge_governance.BRIDGE_MEMBERSHIP_TYPE_STRING;
195
195
  exports.BRIDGE_OWNER_ATTESTATION_TYPE_STRING = require_bridge_governance.BRIDGE_OWNER_ATTESTATION_TYPE_STRING;
196
+ exports.BRIDGE_RELEASE_BUCKET_TAG = require_bridge_governance.BRIDGE_RELEASE_BUCKET_TAG;
197
+ exports.BRIDGE_RELEASE_KEY_PATTERN = require_bridge_governance.BRIDGE_RELEASE_KEY_PATTERN;
198
+ exports.BRIDGE_RELEASE_TOMBSTONE_TAG = require_bridge_governance.BRIDGE_RELEASE_TOMBSTONE_TAG;
196
199
  exports.EIP712_BRIDGE_WITHDRAW_TYPE_STRING = require_envelope.EIP712_BRIDGE_WITHDRAW_TYPE_STRING;
200
+ exports.EIP712_ENVELOPE_DEFAULT_DOMAIN = require_envelope.EIP712_ENVELOPE_DEFAULT_DOMAIN;
197
201
  exports.Hasher = Hasher;
198
202
  exports.Signer = Signer;
199
203
  exports.assertEnvelopeMatchesTxContext = require_envelope.assertEnvelopeMatchesTxContext;
200
204
  exports.bridgeEvidenceKey = require_bridge_governance.bridgeEvidenceKey;
205
+ exports.bridgeReleaseBucketKey = require_bridge_governance.bridgeReleaseBucketKey;
206
+ exports.bridgeReleaseTombstoneKey = require_bridge_governance.bridgeReleaseTombstoneKey;
201
207
  exports.buildBridgeWithdrawEnvelopeExtra = require_envelope.buildBridgeWithdrawEnvelopeExtra;
202
208
  exports.buildEd25519EnvelopePayload = require_envelope.buildEd25519EnvelopePayload;
203
209
  exports.buildSolanaOffchainEnvelopeBytes = require_envelope.buildSolanaOffchainEnvelopeBytes;
@@ -218,6 +224,8 @@ exports.getHasher = getHasher;
218
224
  exports.getRandomBytes = getRandomBytes;
219
225
  exports.getSigner = getSigner;
220
226
  exports.hmacSha256 = require_hasher_sha2.hmacSha256;
227
+ exports.inBridgeReleaseKeySpace = require_bridge_governance.inBridgeReleaseKeySpace;
228
+ exports.isBridgeReleaseKey = require_bridge_governance.isBridgeReleaseKey;
221
229
  exports.isCanonicalWalletEnvelopeExtra = require_envelope.isCanonicalWalletEnvelopeExtra;
222
230
  exports.isStrictEthAddress = require_eth_address.isStrictEthAddress;
223
231
  exports.normalizeChallengeHex = require_envelope.normalizeChallengeHex;
package/lib/index.d.cts CHANGED
@@ -1,5 +1,5 @@
1
- import { BRIDGE_GOV_DOMAIN_NAME, BRIDGE_GOV_DOMAIN_VERSION, BRIDGE_MEMBERSHIP_ACTION, BRIDGE_MEMBERSHIP_TYPE_STRING, BRIDGE_OWNER_ATTESTATION_TYPE_STRING, BridgeKeyPart, BridgeMembershipMessage, BridgeOwnerAttestationMessage, RecoveredBridgeSigner, bridgeEvidenceKey, computeBridgeEndpointsHash, computeBridgeMembershipDigest, computeBridgeOwnerAttestationDigest, ethAddressOfPublicKey, recoverBridgeSigner, signBridgeDigest, toHexDigest } from "./bridge-governance.cjs";
2
- import { EIP712_BRIDGE_WITHDRAW_TYPE_STRING, ExpectedEnvelopeTxContext, WalletEnvelopeExtra, WalletEnvelopeType, assertEnvelopeMatchesTxContext, buildBridgeWithdrawEnvelopeExtra, buildEd25519EnvelopePayload, buildSolanaOffchainEnvelopeBytes, computeEip191EnvelopeDigest, computeEip712EnvelopeDigest, envelope_d_exports, formatWalletEnvelopeText, isCanonicalWalletEnvelopeExtra, normalizeChallengeHex, parseWalletEnvelopeExtra, signEthereumEnvelope, verifyEthereumEnvelope } from "./envelope.cjs";
1
+ import { 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 } from "./bridge-governance.cjs";
2
+ import { EIP712_BRIDGE_WITHDRAW_TYPE_STRING, EIP712_ENVELOPE_DEFAULT_DOMAIN, ExpectedEnvelopeTxContext, WalletEnvelopeExtra, WalletEnvelopeType, assertEnvelopeMatchesTxContext, buildBridgeWithdrawEnvelopeExtra, buildEd25519EnvelopePayload, buildSolanaOffchainEnvelopeBytes, computeEip191EnvelopeDigest, computeEip712EnvelopeDigest, envelope_d_exports, formatWalletEnvelopeText, isCanonicalWalletEnvelopeExtra, normalizeChallengeHex, parseWalletEnvelopeExtra, signEthereumEnvelope, verifyEthereumEnvelope } from "./envelope.cjs";
3
3
  import { StrictEthAddressFailure, StrictEthAddressResult, isStrictEthAddress, parseStrictEthAddress } from "./eth-address.cjs";
4
4
  import { KeccakHasher } from "./hasher/keccak.cjs";
5
5
  import { Sha2Hasher, hmacSha256 } from "./hasher/sha2.cjs";
@@ -243,4 +243,4 @@ declare function getRandomBytes(length: number, encoding?: 'Uint8Array'): Uint8A
243
243
  declare function getRandomBytes(length: number, encoding?: EncodingType): BytesType;
244
244
  declare const toTxHash: (buf: Buffer | Uint8Array) => string;
245
245
  //#endregion
246
- export { AddressType, BRIDGE_GOV_DOMAIN_NAME, BRIDGE_GOV_DOMAIN_VERSION, BRIDGE_MEMBERSHIP_ACTION, BRIDGE_MEMBERSHIP_TYPE_STRING, BRIDGE_OWNER_ATTESTATION_TYPE_STRING, BridgeKeyPart, BridgeMembershipMessage, BridgeOwnerAttestationMessage, EIP712_BRIDGE_WITHDRAW_TYPE_STRING, ExpectedEnvelopeTxContext, HashFnType, HashType, Hasher, KeyType, RecoveredBridgeSigner, RoleType, Signer, SignerType, StrictEthAddressFailure, StrictEthAddressResult, WalletEnvelopeExtra, WalletEnvelopeType, assertEnvelopeMatchesTxContext, bridgeEvidenceKey, buildBridgeWithdrawEnvelopeExtra, buildEd25519EnvelopePayload, buildSolanaOffchainEnvelopeBytes, computeBridgeEndpointsHash, computeBridgeMembershipDigest, computeBridgeOwnerAttestationDigest, computeEip191EnvelopeDigest, computeEip712EnvelopeDigest, envelope_d_exports as envelope, ethAddressOfPublicKey, formatWalletEnvelopeText, getHasher, getRandomBytes, getSigner, hmacSha256, isCanonicalWalletEnvelopeExtra, isStrictEthAddress, normalizeChallengeHex, parseStrictEthAddress, parseWalletEnvelopeExtra, recoverBridgeSigner, signBridgeDigest, signEthereumEnvelope, toHexDigest, toTxHash, types, verifyEthereumEnvelope, webauthn_d_exports as webauthn };
246
+ export { AddressType, 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, EIP712_BRIDGE_WITHDRAW_TYPE_STRING, EIP712_ENVELOPE_DEFAULT_DOMAIN, ExpectedEnvelopeTxContext, HashFnType, HashType, Hasher, KeyType, RecoveredBridgeSigner, RoleType, Signer, SignerType, StrictEthAddressFailure, StrictEthAddressResult, WalletEnvelopeExtra, WalletEnvelopeType, assertEnvelopeMatchesTxContext, bridgeEvidenceKey, bridgeReleaseBucketKey, bridgeReleaseTombstoneKey, buildBridgeWithdrawEnvelopeExtra, buildEd25519EnvelopePayload, buildSolanaOffchainEnvelopeBytes, computeBridgeEndpointsHash, computeBridgeMembershipDigest, computeBridgeOwnerAttestationDigest, computeEip191EnvelopeDigest, computeEip712EnvelopeDigest, envelope_d_exports as envelope, ethAddressOfPublicKey, formatWalletEnvelopeText, getHasher, getRandomBytes, getSigner, hmacSha256, inBridgeReleaseKeySpace, isBridgeReleaseKey, isCanonicalWalletEnvelopeExtra, isStrictEthAddress, normalizeChallengeHex, parseStrictEthAddress, parseWalletEnvelopeExtra, recoverBridgeSigner, signBridgeDigest, signEthereumEnvelope, toHexDigest, toTxHash, types, verifyEthereumEnvelope, webauthn_d_exports as webauthn };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ocap/mcrypto",
3
- "version": "1.31.5",
3
+ "version": "1.31.7",
4
4
  "type": "module",
5
5
  "description": "Crypto lib that provides signer,crypter,hasher interface",
6
6
  "keywords": [
@@ -75,7 +75,7 @@
75
75
  "@noble/curves": "2.2.0",
76
76
  "@noble/ed25519": "3.0.1",
77
77
  "@noble/hashes": "2.2.0",
78
- "@ocap/util": "1.31.5",
78
+ "@ocap/util": "1.31.7",
79
79
  "interface": "^1.2.1",
80
80
  "randombytes": "^2.1.0"
81
81
  },