@invisi-labs/protocol 1.1.3 → 1.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.cts CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as _invisi_labs_core from '@invisi-labs/core';
2
- import { Hex, Address, ReceivingKeyLookup, Wallet, Note, CreditDeliveryState, AuthorizedStatement } from '@invisi-labs/core';
3
- import { ContractRunner, Signer, Provider } from 'ethers';
2
+ import { Hex, Address, ReceivingKeyLookup, PublicWallet, CreditDeliveryState, AuthorizedStatement, Note } from '@invisi-labs/core';
3
+ import { ContractRunner, Provider } from 'ethers';
4
4
  import { DeploymentContext, CanonicalBlock, ProtocolDeployment, ProtocolRpcClient } from '@invisi-labs/rpc';
5
5
  export { CanonicalBlock, DeploymentContext, Membership, ProtocolDataProvider, ProtocolDataStatus, ProtocolUpdateRange, ProtocolUpdates } from '@invisi-labs/rpc';
6
6
  import { F as FundingParams, D as Delivery, I as InputSource, C as CreateCreditParams, a as CancelCreditParams, b as CreditDrawParams, T as TopUpCreditParams, c as TransactRequest, S as ShieldParams, d as ShieldOutput, e as CrossTreeTransactParams } from './types-BCTQjKzw.cjs';
@@ -105,8 +105,8 @@ declare function normalizeSources(sources: readonly InputSource[], inputCount: n
105
105
  merkleRoot: `0x${string}`;
106
106
  }[];
107
107
  declare const pad: (v: readonly bigint[], n: number) => bigint[];
108
- declare function normalizeDelivery(value: Delivery, options?: {
109
- credit?: boolean;
108
+ /** Receipt/transport validation must not reject unrelated future wallet codecs. */
109
+ declare function normalizeOpaqueDelivery(value: Delivery, options?: {
110
110
  empty?: boolean;
111
111
  }): Delivery;
112
112
  declare const deliveriesHash: (v: readonly Delivery[]) => Hex;
@@ -183,9 +183,8 @@ interface RegistryReader extends Pick<ChainReader, "getChainId" | "getCode" | "g
183
183
  getRegistryNonce(context: RegistryContext, walletIdentity: Hex, block: CanonicalBlock): Promise<bigint>;
184
184
  }
185
185
  interface RegistrationPreparation {
186
- wallet: Wallet;
186
+ wallet: PublicWallet;
187
187
  reader: RegistryReader;
188
- signer?: Signer;
189
188
  deadline?: bigint;
190
189
  update?: boolean;
191
190
  }
@@ -207,10 +206,13 @@ declare class RegistrationOperation {
207
206
  chainId: bigint;
208
207
  registryAddress: `0x${string}`;
209
208
  };
210
- /** Sign with ethers, or attach externally obtained ERC-1271 signature bytes. */
211
- authorize(options?: {
209
+ /** Export portable EIP-712 data for external signing. */
210
+ exportRegistrationAuthorization(options?: {
211
+ signal?: AbortSignal;
212
+ }): Promise<_invisi_labs_core.SigningRequest>;
213
+ /** Validate and attach an independently obtained EOA or ERC-1271 signature. */
214
+ withSignature(signature: string, options?: {
212
215
  signal?: AbortSignal;
213
- signature?: Hex;
214
216
  }): Promise<RegistrationOperation>;
215
217
  /** Empty signatures require the transaction sender to be the wallet owner. */
216
218
  authorizeDirect(): Promise<RegistrationOperation>;
@@ -927,16 +929,6 @@ interface VerifyCreditCommitmentParams extends Partial<_invisi_labs_core.CreditP
927
929
  */
928
930
  declare function verifyCreditCommitment(params: VerifyCreditCommitmentParams): Promise<boolean>;
929
931
 
930
- interface BuildWithdrawalCalldataParams extends Omit<BuildTransactCalldataParams, "deliveries"> {
931
- sourceNotes: readonly Note[];
932
- }
933
- /** Prepare a full public withdrawal whose spending authority is already proven in the supplied proof. */
934
- declare function buildWithdrawalCalldata(p: BuildWithdrawalCalldataParams): Promise<{
935
- data: `0x${string}`;
936
- capacity: 112 | 14 | 56 | 168;
937
- approveAmount: bigint;
938
- }>;
939
-
940
932
  interface NoteMembership {
941
933
  note: Note;
942
934
  treeId: bigint;
@@ -1007,4 +999,4 @@ declare class WitnessBuilder {
1007
999
  */
1008
1000
  declare function resolveInstanceAddress(client: ContractRunner, factoryAddress: `0x${string}`, salt: `0x${string}`): Promise<`0x${string}`>;
1009
1001
 
1010
- export { type AddressRegistration, AddressRegistry, type AddressRegistryOptions, type AggregateMemberInput, type BuildCancelCreditCalldataParams, type BuildCreateCreditCalldataParams, type BuildCreditDrawCalldataParams, type BuildShieldCalldataParams, type BuildTopUpCreditCalldataParams, type BuildTransactAggregateCalldataParams, type BuildTransactCalldataParams, type BuildWithdrawalCalldataParams, CREATE_CREDIT_FIELDS, CREDIT_DRAW_CAPACITIES, type CancelCreditWitnessParams, type CanonicalReceipt, type ChainReader, type CreateCreditWitnessParams, type CreditMembership, type DrawCreditWitnessParams, EMPTY_FUNDING, EMPTY_PERMIT, FIELD_MODULUS, type FactoryReader, type FundingInput, type NoteMembership, Protocol, type ProtocolLog, type ProtocolOptions, type RegistrationCalldata, RegistrationOperation, type RegistrationOptions, type RegistrationPreparation, type RegistrationStatus, type RegistryContext, type RegistryReadClient, type RegistryReader, type RegistryReceivingKeys, TRANSACT_CAPACITIES, TokenProtocol, type TokenProtocolOptions, type TopUpCreditWitnessParams, type TransactCapacity, type TransactRequestParams, type TransactWitnessParams, type TransactionCall, type TransactionContext, type VerifyCreditCommitmentParams, type VerifyNoteCommitmentParams, WitnessBuilder, ZERO_ADDRESS, ZERO_WORD, aggregateMemberRequestHash, aggregatePublicInputs, buildCancelCreditCalldata, buildCreateCreditCalldata, buildCreditDrawCalldata, buildRegistrationCalldata, buildShieldCalldata, buildTopUpCreditCalldata, buildTransactAggregateCalldata, buildTransactCalldata, buildWithdrawalCalldata, cancelCreditBaseInputs, cancelCreditPublicInputs, cancelCreditRequestHash, checkDeadline, createCreditBaseInputs, createCreditPublicInputs, createCreditRequestHash, createRegistryReceivingKeyLookup, creditDrawBaseInputs, creditDrawPublicInputs, deliveriesHash, dense, encodeAggregateFundingTypedData, encodeCancelCreditTypedData, encodeCreateCreditFundingTypedData, encodeCreateCreditTypedData, encodeCreditDrawTypedData, encodeCreditProof, encodeShieldFundingTypedData, encodeTopUpCreditFundingTypedData, encodeTopUpCreditTypedData, encodeTransactFundingTypedData, encodeTransactTypedData, envelope, field, fundingFields, getEIP712Domain, known, normalizeContext, normalizeDelivery, normalizeFunding, normalizeSources, normalizeTransactRequest, notes, pad, registrationDigest, registrationTypedData, resolveInstanceAddress, selectCreditDrawCircuit, selectTransactCapacity, shieldFundingRequestHash, topUpCreditBaseInputs, topUpCreditPublicInputs, topUpCreditRequestHash, transactFundingRequestHash, transactPublicInputs, transactUserPublicInputs, uint, validateCancelCreditRequest, validateCreateCreditRequest, validateCreditDrawRequest, validateFundingSubmission, validateShieldRequest, validateTopUpCreditRequest, verifyCreditCommitment, verifyNoteCommitment, word };
1002
+ export { type AddressRegistration, AddressRegistry, type AddressRegistryOptions, type AggregateMemberInput, type BuildCancelCreditCalldataParams, type BuildCreateCreditCalldataParams, type BuildCreditDrawCalldataParams, type BuildShieldCalldataParams, type BuildTopUpCreditCalldataParams, type BuildTransactAggregateCalldataParams, type BuildTransactCalldataParams, CREATE_CREDIT_FIELDS, CREDIT_DRAW_CAPACITIES, type CancelCreditWitnessParams, type CanonicalReceipt, type ChainReader, type CreateCreditWitnessParams, type CreditMembership, type DrawCreditWitnessParams, EMPTY_FUNDING, EMPTY_PERMIT, FIELD_MODULUS, type FactoryReader, type FundingInput, type NoteMembership, Protocol, type ProtocolLog, type ProtocolOptions, type RegistrationCalldata, RegistrationOperation, type RegistrationOptions, type RegistrationPreparation, type RegistrationStatus, type RegistryContext, type RegistryReadClient, type RegistryReader, type RegistryReceivingKeys, TRANSACT_CAPACITIES, TokenProtocol, type TokenProtocolOptions, type TopUpCreditWitnessParams, type TransactCapacity, type TransactRequestParams, type TransactWitnessParams, type TransactionCall, type TransactionContext, type VerifyCreditCommitmentParams, type VerifyNoteCommitmentParams, WitnessBuilder, ZERO_ADDRESS, ZERO_WORD, aggregateMemberRequestHash, aggregatePublicInputs, buildCancelCreditCalldata, buildCreateCreditCalldata, buildCreditDrawCalldata, buildRegistrationCalldata, buildShieldCalldata, buildTopUpCreditCalldata, buildTransactAggregateCalldata, buildTransactCalldata, cancelCreditBaseInputs, cancelCreditPublicInputs, cancelCreditRequestHash, checkDeadline, createCreditBaseInputs, createCreditPublicInputs, createCreditRequestHash, createRegistryReceivingKeyLookup, creditDrawBaseInputs, creditDrawPublicInputs, deliveriesHash, dense, encodeAggregateFundingTypedData, encodeCancelCreditTypedData, encodeCreateCreditFundingTypedData, encodeCreateCreditTypedData, encodeCreditDrawTypedData, encodeCreditProof, encodeShieldFundingTypedData, encodeTopUpCreditFundingTypedData, encodeTopUpCreditTypedData, encodeTransactFundingTypedData, encodeTransactTypedData, envelope, field, fundingFields, getEIP712Domain, known, normalizeContext, normalizeFunding, normalizeOpaqueDelivery, normalizeSources, normalizeTransactRequest, notes, pad, registrationDigest, registrationTypedData, resolveInstanceAddress, selectCreditDrawCircuit, selectTransactCapacity, shieldFundingRequestHash, topUpCreditBaseInputs, topUpCreditPublicInputs, topUpCreditRequestHash, transactFundingRequestHash, transactPublicInputs, transactUserPublicInputs, uint, validateCancelCreditRequest, validateCreateCreditRequest, validateCreditDrawRequest, validateFundingSubmission, validateShieldRequest, validateTopUpCreditRequest, verifyCreditCommitment, verifyNoteCommitment, word };
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as _invisi_labs_core from '@invisi-labs/core';
2
- import { Hex, Address, ReceivingKeyLookup, Wallet, Note, CreditDeliveryState, AuthorizedStatement } from '@invisi-labs/core';
3
- import { ContractRunner, Signer, Provider } from 'ethers';
2
+ import { Hex, Address, ReceivingKeyLookup, PublicWallet, CreditDeliveryState, AuthorizedStatement, Note } from '@invisi-labs/core';
3
+ import { ContractRunner, Provider } from 'ethers';
4
4
  import { DeploymentContext, CanonicalBlock, ProtocolDeployment, ProtocolRpcClient } from '@invisi-labs/rpc';
5
5
  export { CanonicalBlock, DeploymentContext, Membership, ProtocolDataProvider, ProtocolDataStatus, ProtocolUpdateRange, ProtocolUpdates } from '@invisi-labs/rpc';
6
6
  import { F as FundingParams, D as Delivery, I as InputSource, C as CreateCreditParams, a as CancelCreditParams, b as CreditDrawParams, T as TopUpCreditParams, c as TransactRequest, S as ShieldParams, d as ShieldOutput, e as CrossTreeTransactParams } from './types-BCTQjKzw.js';
@@ -105,8 +105,8 @@ declare function normalizeSources(sources: readonly InputSource[], inputCount: n
105
105
  merkleRoot: `0x${string}`;
106
106
  }[];
107
107
  declare const pad: (v: readonly bigint[], n: number) => bigint[];
108
- declare function normalizeDelivery(value: Delivery, options?: {
109
- credit?: boolean;
108
+ /** Receipt/transport validation must not reject unrelated future wallet codecs. */
109
+ declare function normalizeOpaqueDelivery(value: Delivery, options?: {
110
110
  empty?: boolean;
111
111
  }): Delivery;
112
112
  declare const deliveriesHash: (v: readonly Delivery[]) => Hex;
@@ -183,9 +183,8 @@ interface RegistryReader extends Pick<ChainReader, "getChainId" | "getCode" | "g
183
183
  getRegistryNonce(context: RegistryContext, walletIdentity: Hex, block: CanonicalBlock): Promise<bigint>;
184
184
  }
185
185
  interface RegistrationPreparation {
186
- wallet: Wallet;
186
+ wallet: PublicWallet;
187
187
  reader: RegistryReader;
188
- signer?: Signer;
189
188
  deadline?: bigint;
190
189
  update?: boolean;
191
190
  }
@@ -207,10 +206,13 @@ declare class RegistrationOperation {
207
206
  chainId: bigint;
208
207
  registryAddress: `0x${string}`;
209
208
  };
210
- /** Sign with ethers, or attach externally obtained ERC-1271 signature bytes. */
211
- authorize(options?: {
209
+ /** Export portable EIP-712 data for external signing. */
210
+ exportRegistrationAuthorization(options?: {
211
+ signal?: AbortSignal;
212
+ }): Promise<_invisi_labs_core.SigningRequest>;
213
+ /** Validate and attach an independently obtained EOA or ERC-1271 signature. */
214
+ withSignature(signature: string, options?: {
212
215
  signal?: AbortSignal;
213
- signature?: Hex;
214
216
  }): Promise<RegistrationOperation>;
215
217
  /** Empty signatures require the transaction sender to be the wallet owner. */
216
218
  authorizeDirect(): Promise<RegistrationOperation>;
@@ -927,16 +929,6 @@ interface VerifyCreditCommitmentParams extends Partial<_invisi_labs_core.CreditP
927
929
  */
928
930
  declare function verifyCreditCommitment(params: VerifyCreditCommitmentParams): Promise<boolean>;
929
931
 
930
- interface BuildWithdrawalCalldataParams extends Omit<BuildTransactCalldataParams, "deliveries"> {
931
- sourceNotes: readonly Note[];
932
- }
933
- /** Prepare a full public withdrawal whose spending authority is already proven in the supplied proof. */
934
- declare function buildWithdrawalCalldata(p: BuildWithdrawalCalldataParams): Promise<{
935
- data: `0x${string}`;
936
- capacity: 112 | 14 | 56 | 168;
937
- approveAmount: bigint;
938
- }>;
939
-
940
932
  interface NoteMembership {
941
933
  note: Note;
942
934
  treeId: bigint;
@@ -1007,4 +999,4 @@ declare class WitnessBuilder {
1007
999
  */
1008
1000
  declare function resolveInstanceAddress(client: ContractRunner, factoryAddress: `0x${string}`, salt: `0x${string}`): Promise<`0x${string}`>;
1009
1001
 
1010
- export { type AddressRegistration, AddressRegistry, type AddressRegistryOptions, type AggregateMemberInput, type BuildCancelCreditCalldataParams, type BuildCreateCreditCalldataParams, type BuildCreditDrawCalldataParams, type BuildShieldCalldataParams, type BuildTopUpCreditCalldataParams, type BuildTransactAggregateCalldataParams, type BuildTransactCalldataParams, type BuildWithdrawalCalldataParams, CREATE_CREDIT_FIELDS, CREDIT_DRAW_CAPACITIES, type CancelCreditWitnessParams, type CanonicalReceipt, type ChainReader, type CreateCreditWitnessParams, type CreditMembership, type DrawCreditWitnessParams, EMPTY_FUNDING, EMPTY_PERMIT, FIELD_MODULUS, type FactoryReader, type FundingInput, type NoteMembership, Protocol, type ProtocolLog, type ProtocolOptions, type RegistrationCalldata, RegistrationOperation, type RegistrationOptions, type RegistrationPreparation, type RegistrationStatus, type RegistryContext, type RegistryReadClient, type RegistryReader, type RegistryReceivingKeys, TRANSACT_CAPACITIES, TokenProtocol, type TokenProtocolOptions, type TopUpCreditWitnessParams, type TransactCapacity, type TransactRequestParams, type TransactWitnessParams, type TransactionCall, type TransactionContext, type VerifyCreditCommitmentParams, type VerifyNoteCommitmentParams, WitnessBuilder, ZERO_ADDRESS, ZERO_WORD, aggregateMemberRequestHash, aggregatePublicInputs, buildCancelCreditCalldata, buildCreateCreditCalldata, buildCreditDrawCalldata, buildRegistrationCalldata, buildShieldCalldata, buildTopUpCreditCalldata, buildTransactAggregateCalldata, buildTransactCalldata, buildWithdrawalCalldata, cancelCreditBaseInputs, cancelCreditPublicInputs, cancelCreditRequestHash, checkDeadline, createCreditBaseInputs, createCreditPublicInputs, createCreditRequestHash, createRegistryReceivingKeyLookup, creditDrawBaseInputs, creditDrawPublicInputs, deliveriesHash, dense, encodeAggregateFundingTypedData, encodeCancelCreditTypedData, encodeCreateCreditFundingTypedData, encodeCreateCreditTypedData, encodeCreditDrawTypedData, encodeCreditProof, encodeShieldFundingTypedData, encodeTopUpCreditFundingTypedData, encodeTopUpCreditTypedData, encodeTransactFundingTypedData, encodeTransactTypedData, envelope, field, fundingFields, getEIP712Domain, known, normalizeContext, normalizeDelivery, normalizeFunding, normalizeSources, normalizeTransactRequest, notes, pad, registrationDigest, registrationTypedData, resolveInstanceAddress, selectCreditDrawCircuit, selectTransactCapacity, shieldFundingRequestHash, topUpCreditBaseInputs, topUpCreditPublicInputs, topUpCreditRequestHash, transactFundingRequestHash, transactPublicInputs, transactUserPublicInputs, uint, validateCancelCreditRequest, validateCreateCreditRequest, validateCreditDrawRequest, validateFundingSubmission, validateShieldRequest, validateTopUpCreditRequest, verifyCreditCommitment, verifyNoteCommitment, word };
1002
+ export { type AddressRegistration, AddressRegistry, type AddressRegistryOptions, type AggregateMemberInput, type BuildCancelCreditCalldataParams, type BuildCreateCreditCalldataParams, type BuildCreditDrawCalldataParams, type BuildShieldCalldataParams, type BuildTopUpCreditCalldataParams, type BuildTransactAggregateCalldataParams, type BuildTransactCalldataParams, CREATE_CREDIT_FIELDS, CREDIT_DRAW_CAPACITIES, type CancelCreditWitnessParams, type CanonicalReceipt, type ChainReader, type CreateCreditWitnessParams, type CreditMembership, type DrawCreditWitnessParams, EMPTY_FUNDING, EMPTY_PERMIT, FIELD_MODULUS, type FactoryReader, type FundingInput, type NoteMembership, Protocol, type ProtocolLog, type ProtocolOptions, type RegistrationCalldata, RegistrationOperation, type RegistrationOptions, type RegistrationPreparation, type RegistrationStatus, type RegistryContext, type RegistryReadClient, type RegistryReader, type RegistryReceivingKeys, TRANSACT_CAPACITIES, TokenProtocol, type TokenProtocolOptions, type TopUpCreditWitnessParams, type TransactCapacity, type TransactRequestParams, type TransactWitnessParams, type TransactionCall, type TransactionContext, type VerifyCreditCommitmentParams, type VerifyNoteCommitmentParams, WitnessBuilder, ZERO_ADDRESS, ZERO_WORD, aggregateMemberRequestHash, aggregatePublicInputs, buildCancelCreditCalldata, buildCreateCreditCalldata, buildCreditDrawCalldata, buildRegistrationCalldata, buildShieldCalldata, buildTopUpCreditCalldata, buildTransactAggregateCalldata, buildTransactCalldata, cancelCreditBaseInputs, cancelCreditPublicInputs, cancelCreditRequestHash, checkDeadline, createCreditBaseInputs, createCreditPublicInputs, createCreditRequestHash, createRegistryReceivingKeyLookup, creditDrawBaseInputs, creditDrawPublicInputs, deliveriesHash, dense, encodeAggregateFundingTypedData, encodeCancelCreditTypedData, encodeCreateCreditFundingTypedData, encodeCreateCreditTypedData, encodeCreditDrawTypedData, encodeCreditProof, encodeShieldFundingTypedData, encodeTopUpCreditFundingTypedData, encodeTopUpCreditTypedData, encodeTransactFundingTypedData, encodeTransactTypedData, envelope, field, fundingFields, getEIP712Domain, known, normalizeContext, normalizeFunding, normalizeOpaqueDelivery, normalizeSources, normalizeTransactRequest, notes, pad, registrationDigest, registrationTypedData, resolveInstanceAddress, selectCreditDrawCircuit, selectTransactCapacity, shieldFundingRequestHash, topUpCreditBaseInputs, topUpCreditPublicInputs, topUpCreditRequestHash, transactFundingRequestHash, transactPublicInputs, transactUserPublicInputs, uint, validateCancelCreditRequest, validateCreateCreditRequest, validateCreditDrawRequest, validateFundingSubmission, validateShieldRequest, validateTopUpCreditRequest, verifyCreditCommitment, verifyNoteCommitment, word };
package/dist/index.js CHANGED
@@ -13,7 +13,7 @@ import {
13
13
 
14
14
  // src/RegistrationOperation.ts
15
15
  import { hexlify as hexlify2, Interface as Interface2, getBytes as getBytes2, verifyTypedData } from "ethers";
16
- import { ReceivingAddress as ReceivingAddress2 } from "@invisi-labs/core";
16
+ import { ReceivingAddress as ReceivingAddress2, createSigningRequest } from "@invisi-labs/core";
17
17
 
18
18
  // src/registry.ts
19
19
  import {
@@ -228,27 +228,20 @@ var RegistrationOperation = class _RegistrationOperation {
228
228
  update: this.#plan.update
229
229
  };
230
230
  }
231
- /** Sign with ethers, or attach externally obtained ERC-1271 signature bytes. */
232
- async authorize(options = {}) {
231
+ /** Export portable EIP-712 data for external signing. */
232
+ async exportRegistrationAuthorization(options = {}) {
233
+ check(this.status === "prepared", "registry operation is not awaiting authorization");
234
+ options.signal?.throwIfAborted();
235
+ await this.validateFreshness();
236
+ options.signal?.throwIfAborted();
237
+ return createSigningRequest(this.typedData());
238
+ }
239
+ /** Validate and attach an independently obtained EOA or ERC-1271 signature. */
240
+ async withSignature(signature, options = {}) {
233
241
  check(this.status === "prepared", "registry operation is not awaiting authorization");
234
242
  options.signal?.throwIfAborted();
235
243
  await this.validateFreshness();
236
244
  options.signal?.throwIfAborted();
237
- let signature = options.signature;
238
- if (signature === void 0) {
239
- const signer = this.#runtime.signer;
240
- check(signer, "registry signer capability is missing");
241
- check(
242
- BigInt(await signer.getAddress()) === BigInt(this.#plan.registration.walletIdentity),
243
- "registry signer does not match wallet owner"
244
- );
245
- const typed = this.typedData();
246
- signature = await signer.signTypedData(
247
- typed.domain,
248
- typed.types,
249
- typed.message
250
- );
251
- }
252
245
  check(
253
246
  /^0x(?:[a-fA-F0-9]{2})+$/.test(signature),
254
247
  "registry signature must be nonempty hexadecimal bytes"
@@ -516,6 +509,7 @@ import {
516
509
  import { computeWalletAuthorizationDigest, walletAuthorizationTypedData } from "@invisi-labs/core";
517
510
 
518
511
  // src/validation.ts
512
+ import { MAX_CIPHERTEXT_BYTES } from "@invisi-labs/core";
519
513
  import {
520
514
  AbiCoder,
521
515
  dataLength,
@@ -610,19 +604,14 @@ var pad = (v, n) => [
610
604
  ...v,
611
605
  ...Array(n - v.length).fill(0n)
612
606
  ];
613
- function normalizeDelivery(value, options = {}) {
607
+ function normalizeOpaqueDelivery(value, options = {}) {
614
608
  known(value, ["ciphertext", "clue"], "delivery");
615
609
  if (options.empty) {
616
610
  if (value.ciphertext !== "0x" || value.clue !== "0x")
617
611
  throw new Error("absent output requires an empty delivery");
618
612
  return { ciphertext: "0x", clue: "0x" };
619
613
  }
620
- const ciphertext = envelope(
621
- value.ciphertext,
622
- options.credit ? 498 : 160,
623
- options.credit ? 5 : 2,
624
- options.credit ? 754 : 416
625
- );
614
+ const ciphertext = envelope(value.ciphertext, 1, void 0, MAX_CIPHERTEXT_BYTES);
626
615
  const clue = envelope(value.clue, 68);
627
616
  if (clue.slice(130, 132).toLowerCase() !== "18") throw new Error("clue precision must be 24");
628
617
  return { ciphertext, clue };
@@ -705,7 +694,7 @@ function validateCreateCreditRequest(c, p, cs, funding = {}) {
705
694
  throw new Error("owner must be nonzero and expiry future");
706
695
  if (dense(cs, "deliveries").length !== 3) throw new Error("deliveries count mismatch");
707
696
  const deliveries = cs.map(
708
- (v, i) => normalizeDelivery(v, { credit: i < 2, empty: i === 2 && BigInt(changeCommitment) === 0n })
697
+ (v, i) => normalizeOpaqueDelivery(v, { empty: i === 2 && BigInt(changeCommitment) === 0n })
709
698
  );
710
699
  if (ns.length === 0 && f.amount === 0n)
711
700
  throw new Error("empty inputs require positive funding");
@@ -891,7 +880,7 @@ function validateCreditDrawRequest(c, p, cs) {
891
880
  if (dense(cs, "deliveries").length !== 2 * ns.length)
892
881
  throw new Error("deliveries count mismatch");
893
882
  const deliveries = cs.map(
894
- (v, i) => BigInt(remainderCommitments[Math.floor(i / 2)]) === 0n ? normalizeDelivery(v, { empty: true }) : normalizeDelivery(v, { credit: true })
883
+ (v, i) => BigInt(remainderCommitments[Math.floor(i / 2)]) === 0n ? normalizeOpaqueDelivery(v, { empty: true }) : normalizeOpaqueDelivery(v, {})
895
884
  );
896
885
  return {
897
886
  ...ctx,
@@ -1153,7 +1142,7 @@ function normalizeTransactRequest(c, p, cs, funding = {}) {
1153
1142
  "deadline"
1154
1143
  ]);
1155
1144
  const ns = notes(p.nullifiers, "nullifiers"), os = notes(p.outputCommitments, "outputCommitments"), capacity = selectTransactCapacity(ns.length, os.length);
1156
- const sources = normalizeSources(p.sources, ns.length, capacity), deliveries = dense(cs, "deliveries").map((v) => normalizeDelivery(v));
1145
+ const sources = normalizeSources(p.sources, ns.length, capacity), deliveries = dense(cs, "deliveries").map((v) => normalizeOpaqueDelivery(v));
1157
1146
  if (deliveries.length !== os.length) throw new Error("deliveries count mismatch");
1158
1147
  const withdrawalAmount = uint(p.withdrawalAmount, 128, "withdrawalAmount"), withdrawalAddress = getAddress6(p.withdrawalAddress), f = normalizeFunding(funding);
1159
1148
  if (withdrawalAmount === 0n !== (BigInt(withdrawalAddress) === 0n) || os.length === 0 && withdrawalAmount === 0n)
@@ -1332,7 +1321,7 @@ async function validateShieldRequest(p) {
1332
1321
  uint(o.amount, 128, "amount");
1333
1322
  if (o.amount === 0n) throw new Error("amount must be positive");
1334
1323
  field(o.identity);
1335
- normalizeDelivery(cs[i]);
1324
+ normalizeOpaqueDelivery(cs[i]);
1336
1325
  if (await computeNoteCommitment(
1337
1326
  p.context.chainId,
1338
1327
  o.identity,
@@ -1664,40 +1653,6 @@ async function verifyCreditCommitment(params) {
1664
1653
  return BigInt(expected) === BigInt(params.creditCommitment);
1665
1654
  }
1666
1655
 
1667
- // src/withdrawal.ts
1668
- import {
1669
- computeNoteCommitment as computeNoteCommitment3,
1670
- computeNoteIdentity as computeNoteIdentity2,
1671
- computeNoteNullifier
1672
- } from "@invisi-labs/core";
1673
- async function buildWithdrawalCalldata(p) {
1674
- const r = normalizeTransactRequest(p.context, p.params, [], p.funding);
1675
- if (r.outputCount !== 0 || r.depositAmount !== 0n || p.sourceNotes.length === 0 || p.sourceNotes.length !== r.inputCount) {
1676
- throw new Error("full withdrawal requires inputs, no private outputs and no funding");
1677
- }
1678
- const walletIdentity = BigInt(p.sourceNotes[0].walletIdentity);
1679
- let total = 0n;
1680
- for (const [index, note] of p.sourceNotes.entries()) {
1681
- if (note.chainId !== p.context.chainId || note.protocolAddress !== BigInt(p.context.protocolAddress))
1682
- throw new Error("source note context mismatch");
1683
- if (BigInt(note.walletIdentity) !== walletIdentity || note.tokenAddress !== BigInt(p.context.tokenAddress) || note.amount <= 0n)
1684
- throw new Error("source note wallet/token/amount mismatch");
1685
- const commitment = await computeNoteCommitment3(
1686
- note.chainId,
1687
- await computeNoteIdentity2(walletIdentity, note.nonce),
1688
- note.tokenAddress,
1689
- note.amount
1690
- );
1691
- const nullifier = await computeNoteNullifier(note.chainId, note.nonce, commitment);
1692
- if (nullifier.toLowerCase() !== r.nullifiers[index].toLowerCase())
1693
- throw new Error("source note nullifier mismatch");
1694
- total += note.amount;
1695
- }
1696
- if (r.withdrawalAmount !== total)
1697
- throw new Error("withdrawal must equal the full input balance");
1698
- return buildTransactCalldata({ ...p, deliveries: [] });
1699
- }
1700
-
1701
1656
  // src/witness.ts
1702
1657
  import {
1703
1658
  computeCreditCommitment as computeCreditCommitment2,
@@ -1705,9 +1660,9 @@ import {
1705
1660
  applyCreditDrawUsage,
1706
1661
  computeCreditNullifier,
1707
1662
  computeCreditSharedKeyHash as computeCreditSharedKeyHash2,
1708
- computeNoteCommitment as computeNoteCommitment4,
1709
- computeNoteIdentity as computeNoteIdentity3,
1710
- computeNoteNullifier as computeNoteNullifier2,
1663
+ computeNoteCommitment as computeNoteCommitment3,
1664
+ computeNoteIdentity as computeNoteIdentity2,
1665
+ computeNoteNullifier,
1711
1666
  computeWalletAuthorizationDigest as computeWalletAuthorizationDigest3,
1712
1667
  normalizeCreditDeliveryState,
1713
1668
  poseidonHash,
@@ -3255,9 +3210,9 @@ var WitnessBuilder = class {
3255
3210
  }
3256
3211
  async noteLeaf(note) {
3257
3212
  this.context(note);
3258
- return computeNoteCommitment4(
3213
+ return computeNoteCommitment3(
3259
3214
  note.chainId,
3260
- await computeNoteIdentity3(BigInt(note.walletIdentity), note.nonce),
3215
+ await computeNoteIdentity2(BigInt(note.walletIdentity), note.nonce),
3261
3216
  note.tokenAddress,
3262
3217
  note.amount
3263
3218
  );
@@ -3285,7 +3240,7 @@ var WitnessBuilder = class {
3285
3240
  check2(input.note.walletIdentity === identity, "input wallet mismatch");
3286
3241
  const leaf = await this.noteLeaf(input.note);
3287
3242
  check2(
3288
- await computeNoteNullifier2(input.note.chainId, input.note.nonce, leaf) === nullifiers[i],
3243
+ await computeNoteNullifier(input.note.chainId, input.note.nonce, leaf) === nullifiers[i],
3289
3244
  "input nullifier mismatch"
3290
3245
  );
3291
3246
  return BigInt(await this.membership(leaf, input, sources));
@@ -3629,7 +3584,6 @@ export {
3629
3584
  buildTopUpCreditCalldata,
3630
3585
  buildTransactAggregateCalldata,
3631
3586
  buildTransactCalldata,
3632
- buildWithdrawalCalldata,
3633
3587
  cancelCreditBaseInputs,
3634
3588
  cancelCreditPublicInputs,
3635
3589
  cancelCreditRequestHash,
@@ -3659,8 +3613,8 @@ export {
3659
3613
  getEIP712Domain,
3660
3614
  known,
3661
3615
  normalizeContext,
3662
- normalizeDelivery,
3663
3616
  normalizeFunding,
3617
+ normalizeOpaqueDelivery,
3664
3618
  normalizeSources,
3665
3619
  normalizeTransactRequest,
3666
3620
  notes,