@orbinum/sdk 0.5.0 → 0.6.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/dist/index.mjs CHANGED
@@ -1190,6 +1190,46 @@ var IndexerClient = class {
1190
1190
  `/shielded/address/${encodeURIComponent(address.toLowerCase())}${qs}`
1191
1191
  );
1192
1192
  }
1193
+ // ─── Relayers ──────────────────────────────────────────────────────────────
1194
+ /** Returns a paginated list of relayers. Filter by active status with `active`. */
1195
+ async getRelayers(params) {
1196
+ const qs = this.buildQuery({
1197
+ page: params?.page,
1198
+ limit: params?.limit,
1199
+ active: params?.active === void 0 ? void 0 : params.active ? "true" : "false"
1200
+ });
1201
+ return this.get(`/relayers${qs}`);
1202
+ }
1203
+ /** Returns a single relayer by EVM address, or null if not found. */
1204
+ async getRelayer(evmAddress) {
1205
+ return this.getOrNull(`/relayers/${encodeURIComponent(evmAddress.toLowerCase())}`);
1206
+ }
1207
+ /** Returns a paginated list of relay fee events. */
1208
+ async getRelayFees(params) {
1209
+ const qs = this.buildQuery({
1210
+ page: params?.page,
1211
+ limit: params?.limit,
1212
+ relayer: params?.relayer,
1213
+ type: params?.type
1214
+ });
1215
+ return this.get(`/relayers/fees${qs}`);
1216
+ }
1217
+ /** Returns aggregated relay fee balances per asset for a given relayer account. */
1218
+ async getRelayFeesSummary(relayer) {
1219
+ return this.get(
1220
+ `/relayers/fees/summary/${encodeURIComponent(relayer)}`
1221
+ );
1222
+ }
1223
+ // ─── Registered assets ─────────────────────────────────────────────────────
1224
+ /** Returns a paginated list of assets registered via register_asset. */
1225
+ async getRegisteredAssets(params) {
1226
+ const qs = this.buildQuery({ page: params?.page, limit: params?.limit });
1227
+ return this.get(`/shielded/assets${qs}`);
1228
+ }
1229
+ /** Returns a single registered asset by its ID, or null if not found. */
1230
+ async getRegisteredAsset(assetId) {
1231
+ return this.getOrNull(`/shielded/assets/${encodeURIComponent(assetId)}`);
1232
+ }
1193
1233
  // ─── Stats & Health ────────────────────────────────────────────────────────
1194
1234
  /** Returns aggregated indexer statistics. */
1195
1235
  async getStats() {
@@ -1774,7 +1814,7 @@ var ShieldedPoolModule = class {
1774
1814
  /**
1775
1815
  * Claims accrued relay fees into the shielded pool.
1776
1816
  * This is a SIGNED transaction — the relayer must sign it with their wallet.
1777
- * Before calling this, generate a ZK disclosure proof with generateFeeClaimProof().
1817
+ * Before calling this, generate a ZK value proof with generateFeeClaimProof() (not yet implemented).
1778
1818
  *
1779
1819
  * Extrinsic: shieldedPool.claim_shielded_fees(commitment, amount, asset_id, memo, proof, public_signals)
1780
1820
  */
@@ -1793,95 +1833,6 @@ var ShieldedPoolModule = class {
1793
1833
  await (txOptions !== void 0 ? tx.signAndSubmit(signer, txOptions) : tx.signAndSubmit(signer))
1794
1834
  );
1795
1835
  }
1796
- // ─── Selective Disclosure ──────────────────────────────────────────────────
1797
- /**
1798
- * Requests a selective disclosure from a target account for a specific commitment.
1799
- * The auditor's Baby Jubjub public key is included so the note owner knows
1800
- * which key to encrypt to when generating the proof.
1801
- * Extrinsic: shieldedPool.request_disclosure(target, commitment, required_fields,
1802
- * reason, auditor_bjj_pk_x, auditor_bjj_pk_y)
1803
- */
1804
- async requestDisclosure(params, signer, txOptions) {
1805
- const entry = resolveTx(this.substrate.unsafe, "ShieldedPool", "request_disclosure");
1806
- const tx = callUnsafeTx(entry, {
1807
- target: params.target,
1808
- commitment: Binary2.fromBytes(new Uint8Array(params.commitment)),
1809
- required_fields: {
1810
- value: params.requiredFields.value,
1811
- asset_id: params.requiredFields.assetId,
1812
- owner: params.requiredFields.owner
1813
- },
1814
- reason: Binary2.fromText(params.reason),
1815
- auditor_bjj_pk_x: Binary2.fromBytes(new Uint8Array(params.auditorBjjPkX)),
1816
- auditor_bjj_pk_y: Binary2.fromBytes(new Uint8Array(params.auditorBjjPkY))
1817
- });
1818
- return toTxResult(
1819
- await (txOptions !== void 0 ? tx.signAndSubmit(signer, txOptions) : tx.signAndSubmit(signer))
1820
- );
1821
- }
1822
- /**
1823
- * Submits a Groth16 ZK disclosure proof for a note commitment.
1824
- * The proof reveals the selected fields (value, asset_id, owner_hash) on-chain.
1825
- * Use generateDisclosureProof() + buildDisclosurePublicSignals() before calling this.
1826
- * Extrinsic: shieldedPool.disclose(commitment, proof_bytes, public_signals, auditor)
1827
- */
1828
- async disclose(params, signer, txOptions) {
1829
- const entry = resolveTx(this.substrate.unsafe, "ShieldedPool", "disclose");
1830
- const tx = callUnsafeTx(entry, {
1831
- commitment: Binary2.fromBytes(new Uint8Array(params.commitment)),
1832
- proof_bytes: Binary2.fromBytes(new Uint8Array(params.proofBytes)),
1833
- public_signals: Binary2.fromBytes(new Uint8Array(params.publicSignals)),
1834
- auditor: params.auditor
1835
- });
1836
- return toTxResult(
1837
- await (txOptions !== void 0 ? tx.signAndSubmit(signer, txOptions) : tx.signAndSubmit(signer))
1838
- );
1839
- }
1840
- /**
1841
- * Rejects a pending disclosure request from an auditor for a specific commitment.
1842
- * Extrinsic: shieldedPool.reject_disclosure(auditor, commitment, reason)
1843
- */
1844
- async rejectDisclosure(params, signer, txOptions) {
1845
- const entry = resolveTx(this.substrate.unsafe, "ShieldedPool", "reject_disclosure");
1846
- const tx = callUnsafeTx(entry, {
1847
- auditor: params.auditor,
1848
- commitment: Binary2.fromBytes(new Uint8Array(params.commitment)),
1849
- reason: Binary2.fromText(params.reason)
1850
- });
1851
- return toTxResult(
1852
- await (txOptions !== void 0 ? tx.signAndSubmit(signer, txOptions) : tx.signAndSubmit(signer))
1853
- );
1854
- }
1855
- /**
1856
- * Cleans up a disclosure request that has passed its expiration block.
1857
- * Permissionless — any account can prune expired requests.
1858
- * Extrinsic: shieldedPool.prune_expired_request(target, auditor, commitment)
1859
- */
1860
- async pruneExpiredRequest(params, signer, txOptions) {
1861
- const entry = resolveTx(this.substrate.unsafe, "ShieldedPool", "prune_expired_request");
1862
- const tx = callUnsafeTx(entry, {
1863
- target: params.target,
1864
- auditor: params.auditor,
1865
- commitment: Binary2.fromBytes(new Uint8Array(params.commitment))
1866
- });
1867
- return toTxResult(
1868
- await (txOptions !== void 0 ? tx.signAndSubmit(signer, txOptions) : tx.signAndSubmit(signer))
1869
- );
1870
- }
1871
- /**
1872
- * Revokes a previously submitted voluntary disclosure record.
1873
- * Only applies to self-disclosures (auditor = None). Auditor-requested records are permanent.
1874
- * Extrinsic: shieldedPool.revoke_disclosure_record(commitment)
1875
- */
1876
- async revokeDisclosureRecord(params, signer, txOptions) {
1877
- const entry = resolveTx(this.substrate.unsafe, "ShieldedPool", "revoke_disclosure_record");
1878
- const tx = callUnsafeTx(entry, {
1879
- commitment: Binary2.fromBytes(new Uint8Array(params.commitment))
1880
- });
1881
- return toTxResult(
1882
- await (txOptions !== void 0 ? tx.signAndSubmit(signer, txOptions) : tx.signAndSubmit(signer))
1883
- );
1884
- }
1885
1836
  };
1886
1837
 
1887
1838
  // src/account-mapping/AccountMappingModule.ts
@@ -2632,14 +2583,8 @@ var SP_SEL = {
2632
2583
  PRIVATE_TRANSFER: new Uint8Array([140, 15, 93, 36]),
2633
2584
  // unshield(bytes,bytes32,bytes32,uint32,uint256,bytes32,uint256,bytes32) → 0xd21d9a79
2634
2585
  UNSHIELD: new Uint8Array([210, 29, 154, 121]),
2635
- // requestDisclosure(bytes32,bytes32,bool,bool,bool,bytes,bytes32,bytes32) 0xe7022933 (caller = auditor)
2636
- REQUEST_DISCLOSURE: new Uint8Array([231, 2, 41, 51]),
2637
- // disclose(bytes32,bytes,bytes,bytes32) → 0xea8a4165 (caller = note owner)
2638
- DISCLOSE: new Uint8Array([234, 138, 65, 101]),
2639
- // rejectDisclosure(bytes32,bytes32,bytes) → 0x72b895a9 (caller = target)
2640
- REJECT_DISCLOSURE: new Uint8Array([114, 184, 149, 169]),
2641
- // pruneExpiredRequest(bytes32,bytes32,bytes32) → 0x0c338dcf (permissionless)
2642
- PRUNE_EXPIRED_REQUEST: new Uint8Array([12, 51, 141, 207])
2586
+ // claimShieldedFees(bytes32,uint256,uint32,bytes,bytes,bytes) 0x42e1e74c
2587
+ CLAIM_SHIELDED_FEES: new Uint8Array([66, 225, 231, 76])
2643
2588
  };
2644
2589
  var KNOWN_PRECOMPILES = {
2645
2590
  // ── Ethereum standard (EIP) ─────────────────────────────────────────────
@@ -2685,10 +2630,7 @@ var KNOWN_PRECOMPILES = {
2685
2630
  "9feb22ea": "shield(uint32,bytes32,bytes)",
2686
2631
  "8c0f5d24": "privateTransfer(bytes,bytes32,bytes32[],bytes32[],bytes[],uint32,uint256)",
2687
2632
  d21d9a79: "unshield(bytes,bytes32,bytes32,uint32,uint256,bytes32,uint256,bytes32)",
2688
- e7022933: "requestDisclosure(bytes32,bytes32,bool,bool,bool,bytes,bytes32,bytes32)",
2689
- ea8a4165: "disclose(bytes32,bytes,bytes,bytes32)",
2690
- "72b895a9": "rejectDisclosure(bytes32,bytes32,bytes)",
2691
- "0c338dcf": "pruneExpiredRequest(bytes32,bytes32,bytes32)"
2633
+ "42e1e74c": "claimShieldedFees(bytes32,uint256,uint32,bytes,bytes,bytes)"
2692
2634
  }
2693
2635
  }
2694
2636
  };
@@ -2851,132 +2793,77 @@ var ShieldedPoolPrecompile = class {
2851
2793
  data: this.buildUnshieldCalldata(params)
2852
2794
  });
2853
2795
  }
2854
- // ─── requestDisclosure ─────────────────────────────────────────────────────
2796
+ // ─── claimShieldedFees ───────────────────────────────────────────────────────────────────
2855
2797
  /**
2856
2798
  * Returns the ABI-encoded calldata for
2857
- * `requestDisclosure(bytes32,bytes32,bool,bool,bool,bytes,bytes32,bytes32)`.
2858
- *
2859
- * The **EVM caller** of the resulting transaction is treated as the **auditor**
2860
- * on-chain. No explicit auditor argument is needed.
2861
- */
2862
- buildRequestDisclosureCalldata(params) {
2863
- if (params.auditorBjjPkX.length !== 32)
2864
- throw new RangeError("requestDisclosure: auditorBjjPkX must be 32 bytes");
2865
- if (params.auditorBjjPkY.length !== 32)
2866
- throw new RangeError("requestDisclosure: auditorBjjPkY must be 32 bytes");
2867
- const target = fromHex(params.target);
2868
- const commitment = fromHex(params.commitment);
2869
- const reasonBytes = new TextEncoder().encode(params.reason);
2870
- return encodeHex(
2871
- SP_SEL.REQUEST_DISCLOSURE,
2872
- { type: "bytes32", value: target },
2873
- { type: "bytes32", value: commitment },
2874
- { type: "bool", value: params.disclosedValue },
2875
- { type: "bool", value: params.disclosedAssetId },
2876
- { type: "bool", value: params.disclosedOwner },
2877
- { type: "bytes", value: reasonBytes },
2878
- { type: "bytes32", value: params.auditorBjjPkX },
2879
- { type: "bytes32", value: params.auditorBjjPkY }
2880
- );
2881
- }
2882
- /**
2883
- * Requests selective disclosure of a specific commitment.
2799
+ * `claimShieldedFees(bytes32,uint256,uint32,bytes,bytes,bytes)`.
2884
2800
  *
2885
- * The EVM caller is recorded as the auditor on-chain. The note owner can
2886
- * respond with `disclose()` or reject with `rejectDisclosure()`.
2801
+ * ABI layout (params after selector):
2802
+ * - `commitment` bytes32 (fixed)
2803
+ * - `amount` — uint256 (fixed)
2804
+ * - `asset_id` — uint32 (fixed, right-aligned)
2805
+ * - `memo` — bytes (dynamic)
2806
+ * - `proof` — bytes (dynamic, 128 bytes Groth16)
2807
+ * - `publicSignals` — bytes (dynamic, 76 bytes)
2887
2808
  *
2888
- * Extrinsic: `shieldedPool.requestDisclosure(target, commitment, requiredFields, reason, bjjPkX, bjjPkY)`
2809
+ * The validator identity is derived from `msg.sender` in the precompile
2810
+ * do NOT include it in the calldata.
2889
2811
  */
2890
- async requestDisclosure(params, signer) {
2891
- return signer({ to: this.addr, data: this.buildRequestDisclosureCalldata(params) });
2892
- }
2893
- // ─── disclose ──────────────────────────────────────────────────────────────
2894
- /**
2895
- * Returns the ABI-encoded calldata for `disclose(bytes32,bytes,bytes,bytes32)`.
2896
- *
2897
- * The **EVM caller** is treated as the **note owner** on-chain.
2898
- * `params.proofBytes` must be exactly 128 bytes; `params.publicSignals` exactly 256 bytes.
2899
- */
2900
- buildDiscloseCalldata(params) {
2901
- if (params.proofBytes.length !== 128)
2902
- throw new RangeError("disclose: proofBytes must be exactly 128 bytes");
2903
- if (params.publicSignals.length !== 256)
2904
- throw new RangeError("disclose: publicSignals must be exactly 256 bytes");
2812
+ buildClaimShieldedFeesCalldata(params) {
2813
+ EncryptedMemo.validate(
2814
+ params.encryptedMemo,
2815
+ "buildClaimShieldedFeesCalldata.encryptedMemo"
2816
+ );
2817
+ if (params.proof.length === 0) {
2818
+ throw new Error("claimShieldedFees: proof must not be empty");
2819
+ }
2820
+ if (params.publicSignals.length !== 76) {
2821
+ throw new Error(
2822
+ `claimShieldedFees: publicSignals must be 76 bytes, got ${params.publicSignals.length}`
2823
+ );
2824
+ }
2905
2825
  const commitment = fromHex(params.commitment);
2906
- const auditor = fromHex(params.auditor);
2907
2826
  return encodeHex(
2908
- SP_SEL.DISCLOSE,
2827
+ SP_SEL.CLAIM_SHIELDED_FEES,
2909
2828
  { type: "bytes32", value: commitment },
2910
- { type: "bytes", value: params.proofBytes },
2911
- { type: "bytes", value: params.publicSignals },
2912
- { type: "bytes32", value: auditor }
2829
+ { type: "uint", value: params.amount },
2830
+ { type: "uint", value: BigInt(params.assetId) },
2831
+ { type: "bytes", value: params.encryptedMemo },
2832
+ { type: "bytes", value: params.proof },
2833
+ { type: "bytes", value: params.publicSignals }
2913
2834
  );
2914
2835
  }
2915
2836
  /**
2916
- * Submits a selective disclosure proof for a commitment.
2837
+ * Claims accumulated relay fees as a private shielded note.
2917
2838
  *
2918
- * The EVM caller is treated as the note owner on-chain. The Groth16 proof is
2919
- * verified by the runtime; on success the encrypted signals are stored for
2920
- * the auditor to decrypt off-chain.
2921
- *
2922
- * Extrinsic: `shieldedPool.disclose(commitment, proofBytes, publicSignals, auditor)`
2923
- */
2924
- async disclose(params, signer) {
2925
- return signer({ to: this.addr, data: this.buildDiscloseCalldata(params) });
2926
- }
2927
- // ─── rejectDisclosure ──────────────────────────────────────────────────────
2928
- /**
2929
- * Returns the ABI-encoded calldata for `rejectDisclosure(bytes32,bytes32,bytes)`.
2839
+ * This extrinsic is for **validators/relayers** who have accrued fees in
2840
+ * `pallet-relayer` and want to receive them privately inside the shielded pool
2841
+ * instead of as a public balance credit.
2930
2842
  *
2931
- * The **EVM caller** is treated as the **target** (note owner) on-chain.
2932
- */
2933
- buildRejectDisclosureCalldata(params) {
2934
- const auditor = fromHex(params.auditor);
2935
- const commitment = fromHex(params.commitment);
2936
- const reasonBytes = new TextEncoder().encode(params.reason);
2937
- return encodeHex(
2938
- SP_SEL.REJECT_DISCLOSURE,
2939
- { type: "bytes32", value: auditor },
2940
- { type: "bytes32", value: commitment },
2941
- { type: "bytes", value: reasonBytes }
2942
- );
2943
- }
2944
- /**
2945
- * Rejects a pending disclosure request.
2843
+ * The ZK `value_proof` binds `commitment` to `(amount, assetId, ownerPk, blinding)`
2844
+ * so the runtime can verify the note encodes exactly the claimed fee amount,
2845
+ * preventing a malicious relayer from inflating the withdrawal.
2946
2846
  *
2947
- * The EVM caller is treated as the note owner (target) on-chain.
2847
+ * The `msg.sender` EVM address is used as the validator identity; it must match
2848
+ * the address that has pending relay fees in `pallet-relayer`.
2948
2849
  *
2949
- * Extrinsic: `shieldedPool.rejectDisclosure(auditor, commitment, reason)`
2850
+ * Extrinsic: `shieldedPool.claim_shielded_fees(commitment, amount, assetId, memo, proof, publicSignals)`
2950
2851
  */
2951
- async rejectDisclosure(params, signer) {
2952
- return signer({ to: this.addr, data: this.buildRejectDisclosureCalldata(params) });
2852
+ async claimShieldedFees(params, signer) {
2853
+ return signer({
2854
+ to: this.addr,
2855
+ data: this.buildClaimShieldedFeesCalldata(params)
2856
+ });
2953
2857
  }
2954
- // ─── pruneExpiredRequest ───────────────────────────────────────────────────
2955
2858
  /**
2956
- * Returns the ABI-encoded calldata for `pruneExpiredRequest(bytes32,bytes32,bytes32)`.
2957
- *
2958
- * Permissionless: any EVM caller can prune an expired request.
2859
+ * Estimates the EVM gas for a `claimShieldedFees` call.
2959
2860
  */
2960
- buildPruneExpiredRequestCalldata(params) {
2961
- const target = fromHex(params.target);
2962
- const auditor = fromHex(params.auditor);
2963
- const commitment = fromHex(params.commitment);
2964
- return encodeHex(
2965
- SP_SEL.PRUNE_EXPIRED_REQUEST,
2966
- { type: "bytes32", value: target },
2967
- { type: "bytes32", value: auditor },
2968
- { type: "bytes32", value: commitment }
2969
- );
2970
- }
2971
- /**
2972
- * Removes an expired disclosure request from storage.
2973
- *
2974
- * Permissionless: any EVM account can call this once `expires_at` has passed.
2975
- *
2976
- * Extrinsic: `shieldedPool.pruneExpiredRequest(target, auditor, commitment)`
2977
- */
2978
- async pruneExpiredRequest(params, signer) {
2979
- return signer({ to: this.addr, data: this.buildPruneExpiredRequestCalldata(params) });
2861
+ async estimateClaimShieldedFeesGas(params, from) {
2862
+ return this.evm.estimateGas({
2863
+ from,
2864
+ to: this.addr,
2865
+ data: this.buildClaimShieldedFeesCalldata(params)
2866
+ });
2980
2867
  }
2981
2868
  };
2982
2869
 
@@ -3985,6 +3872,56 @@ function tryDecryptNoteVerbose(commitment, viewingSecretKey, spendingKey, ownOwn
3985
3872
  };
3986
3873
  }
3987
3874
 
3875
+ // src/shielded-pool/protocol/NoteDisclosure.ts
3876
+ import { poseidon4 as poseidon43 } from "poseidon-lite";
3877
+ var PREFIX = "orbdisc:";
3878
+ var VERSION = 1;
3879
+ function toHex2(n) {
3880
+ return "0x" + n.toString(16);
3881
+ }
3882
+ function fromHex2(s) {
3883
+ return BigInt(s);
3884
+ }
3885
+ function createNoteDisclosureKey(note) {
3886
+ const payload = {
3887
+ v: VERSION,
3888
+ c: toHex2(note.commitment),
3889
+ val: toHex2(note.value),
3890
+ aid: toHex2(note.assetId),
3891
+ opk: toHex2(note.ownerPk),
3892
+ bld: toHex2(note.blinding)
3893
+ };
3894
+ const json = JSON.stringify(payload);
3895
+ const b64 = btoa(json).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
3896
+ return PREFIX + b64;
3897
+ }
3898
+ function decodeNoteDisclosureKey(key) {
3899
+ try {
3900
+ if (!key.startsWith(PREFIX)) return null;
3901
+ const b64 = key.slice(PREFIX.length).replace(/-/g, "+").replace(/_/g, "/");
3902
+ const json = atob(b64);
3903
+ const payload = JSON.parse(json);
3904
+ if (payload.v !== VERSION) return null;
3905
+ const disclosure = {
3906
+ commitment: fromHex2(payload.c),
3907
+ value: fromHex2(payload.val),
3908
+ assetId: fromHex2(payload.aid),
3909
+ ownerPk: fromHex2(payload.opk),
3910
+ blinding: fromHex2(payload.bld)
3911
+ };
3912
+ const recomputed = poseidon43([
3913
+ disclosure.value,
3914
+ disclosure.assetId,
3915
+ disclosure.ownerPk,
3916
+ disclosure.blinding
3917
+ ]);
3918
+ if (recomputed !== disclosure.commitment) return null;
3919
+ return disclosure;
3920
+ } catch {
3921
+ return null;
3922
+ }
3923
+ }
3924
+
3988
3925
  // src/shielded-pool/protocol/coinSelection.ts
3989
3926
  var TRANSFER_TREE_DEPTH = 20;
3990
3927
  function selectNotes(notes, needed) {
@@ -4021,51 +3958,6 @@ function buildDummyTransferInput(assetId) {
4021
3958
  };
4022
3959
  }
4023
3960
 
4024
- // src/shielded-pool/protocol/disclosure.ts
4025
- import {
4026
- generateDisclosureProof
4027
- } from "@orbinum/proof-generator";
4028
- import { mulPointEscalar as mulPointEscalar5, Base8 as Base83 } from "@zk-kit/baby-jubjub";
4029
- import { poseidon1, poseidon3 } from "poseidon-lite";
4030
- function hexFieldToBytes32(hex) {
4031
- const clean = hex.startsWith("0x") || hex.startsWith("0X") ? hex.slice(2) : hex;
4032
- return fromHex(clean.padStart(64, "0"));
4033
- }
4034
- function deriveBabyJubjubKeypair(substrateSigningKey) {
4035
- let keyBigInt = 0n;
4036
- for (let i = 0; i < substrateSigningKey.length; i++) {
4037
- keyBigInt = keyBigInt << 8n | BigInt(substrateSigningKey[i]);
4038
- }
4039
- const sk = poseidon1([keyBigInt]);
4040
- const pk = mulPointEscalar5(Base83, sk);
4041
- return { sk, pkX: pk[0], pkY: pk[1] };
4042
- }
4043
- function buildDisclosurePublicSignals(commitment, auditorPkX, auditorPkY, proofOutput) {
4044
- const buf = new Uint8Array(256);
4045
- buf.set(hexFieldToBytes32(commitment), 0);
4046
- buf.set(bigintTo32Le(auditorPkX), 32);
4047
- buf.set(bigintTo32Le(auditorPkY), 64);
4048
- buf.set(hexFieldToBytes32(proofOutput.encryptedData.epkX), 96);
4049
- buf.set(hexFieldToBytes32(proofOutput.encryptedData.epkY), 128);
4050
- buf.set(hexFieldToBytes32(proofOutput.encryptedData.encValue), 160);
4051
- buf.set(hexFieldToBytes32(proofOutput.encryptedData.encAssetId), 192);
4052
- buf.set(hexFieldToBytes32(proofOutput.encryptedData.encOwnerHash), 224);
4053
- return Array.from(buf);
4054
- }
4055
- function decryptDisclosureSignals(auditorBjjSk, enc) {
4056
- const shared = mulPointEscalar5([enc.epkX, enc.epkY], auditorBjjSk);
4057
- const sharedX = shared[0];
4058
- const sharedY = shared[1];
4059
- const k0 = poseidon3([sharedX, sharedY, 0n]);
4060
- const k1 = poseidon3([sharedX, sharedY, 1n]);
4061
- const k2 = poseidon3([sharedX, sharedY, 2n]);
4062
- return {
4063
- value: (enc.encValue - k0 + BN254_R) % BN254_R,
4064
- assetId: (enc.encAssetId - k1 + BN254_R) % BN254_R,
4065
- ownerHash: (enc.encOwnerHash - k2 + BN254_R) % BN254_R
4066
- };
4067
- }
4068
-
4069
3961
  // src/utils/blinding.ts
4070
3962
  function randomBlinding() {
4071
3963
  const buf = new Uint8Array(32);
@@ -4077,7 +3969,7 @@ function randomBlinding() {
4077
3969
  // src/privacy-keys/PrivacyKeys.ts
4078
3970
  import { hkdf as hkdf2 } from "@noble/hashes/hkdf.js";
4079
3971
  import { sha256 as sha2563 } from "@noble/hashes/sha2.js";
4080
- import { mulPointEscalar as mulPointEscalar6, Base8 as Base84, packPoint as packPoint2 } from "@zk-kit/baby-jubjub";
3972
+ import { mulPointEscalar as mulPointEscalar5, Base8 as Base83, packPoint as packPoint2 } from "@zk-kit/baby-jubjub";
4081
3973
  var IVK_DOMAIN = new TextEncoder().encode("orbinum-ivk-v1");
4082
3974
  function deriveSpendingKeyMessage(chainId, address) {
4083
3975
  return `orbinum-spending-key-v1
@@ -4100,13 +3992,13 @@ function deriveViewingSecretKey(spendingKey) {
4100
3992
  }
4101
3993
  function deriveViewingPublicKey(ivsk) {
4102
3994
  const ivskScalar = BigInt(toHex(ivsk)) % BABYJUB_SUBORDER || 1n;
4103
- const ivkPoint = mulPointEscalar6(Base84, ivskScalar);
3995
+ const ivkPoint = mulPointEscalar5(Base83, ivskScalar);
4104
3996
  const packed = packPoint2(ivkPoint);
4105
3997
  return bigintTo32Le(packed);
4106
3998
  }
4107
3999
  function deriveOwnerPk(spendingKey) {
4108
4000
  try {
4109
- const pubPoint = mulPointEscalar6(Base84, spendingKey);
4001
+ const pubPoint = mulPointEscalar5(Base83, spendingKey);
4110
4002
  return pubPoint[0];
4111
4003
  } catch {
4112
4004
  return 0n;
@@ -4383,8 +4275,8 @@ import {
4383
4275
  WebArtifactProvider
4384
4276
  } from "@orbinum/proof-generator";
4385
4277
  import { randomBytes as randomBytes3 } from "@noble/ciphers/utils.js";
4386
- import { mulPointEscalar as mulPointEscalar7, Base8 as Base85 } from "@zk-kit/baby-jubjub";
4387
- import { poseidon4 as poseidon43 } from "poseidon-lite";
4278
+ import { mulPointEscalar as mulPointEscalar6, Base8 as Base84 } from "@zk-kit/baby-jubjub";
4279
+ import { poseidon4 as poseidon44 } from "poseidon-lite";
4388
4280
 
4389
4281
  // src/proof-generator/merkle.ts
4390
4282
  function merkleProofToCircuit(siblings, leafIndex) {
@@ -4406,9 +4298,9 @@ async function generateUnshieldProof(inputs, options = {}) {
4406
4298
  if (changeValue < 0n) {
4407
4299
  throw new Error("changeValue must be >= 0.");
4408
4300
  }
4409
- const changeOwnerPubkey = inputs.changeOwnerPubkey ?? mulPointEscalar7(Base85, inputs.spendingKey)[0];
4301
+ const changeOwnerPubkey = inputs.changeOwnerPubkey ?? mulPointEscalar6(Base84, inputs.spendingKey)[0];
4410
4302
  const changeBlinding = inputs.changeBlinding ?? (changeValue > 0n ? bytesToBigintLE(randomBytes3(32)) : 0n);
4411
- const changeCommitment = changeValue > 0n ? poseidon43([changeValue, inputs.assetId, changeOwnerPubkey, changeBlinding]) : 0n;
4303
+ const changeCommitment = changeValue > 0n ? poseidon44([changeValue, inputs.assetId, changeOwnerPubkey, changeBlinding]) : 0n;
4412
4304
  const circuitInputs = {
4413
4305
  merkle_root: leHexToBigint(inputs.merkleRoot).toString(),
4414
4306
  nullifier: inputs.nullifier.toString(),
@@ -4472,41 +4364,34 @@ async function generateTransferProof(params, options = {}) {
4472
4364
 
4473
4365
  // src/proof-generator/fee-claim.ts
4474
4366
  import {
4475
- generateDisclosureProof as generateDisclosureProof2
4367
+ CircuitType as CircuitType3,
4368
+ generateProof as generateProof3,
4369
+ WebArtifactProvider as WebArtifactProvider3
4476
4370
  } from "@orbinum/proof-generator";
4477
- function hexSignalToBytes(hex) {
4478
- const clean = hex.startsWith("0x") || hex.startsWith("0X") ? hex.slice(2) : hex;
4479
- const padded = clean.padStart(64, "0");
4480
- const bytes = new Uint8Array(32);
4481
- for (let i = 0; i < 32; i++) {
4482
- bytes[i] = parseInt(padded.slice(i * 2, i * 2 + 2), 16);
4483
- }
4484
- return bytes;
4485
- }
4486
4371
  async function generateFeeClaimProof(inputs, options = {}) {
4487
- const result = await generateDisclosureProof2(
4488
- inputs.amount,
4489
- inputs.ownerPubkey,
4490
- inputs.blinding,
4491
- inputs.assetId,
4492
- inputs.commitment,
4493
- // Baby Jubjub base point G — placeholder, no real auditor for fee claiming
4494
- 5299619240641551281634865583518297030282874472190772894086521144482721001553n,
4495
- 16950150798460657717958625567821834550301663161624707787222815936182638968203n,
4496
- 1n,
4497
- // r placeholder ephemeral scalar (NOT cryptographically secure)
4498
- { discloseValue: true, discloseAssetId: true, discloseOwner: false },
4499
- options
4500
- );
4501
- const [, , sigEncValue, sigEncAssetId, sigEncOwnerHash, sigCommitment] = result.publicSignals.map(hexSignalToBytes);
4502
- const compact = new Uint8Array(76);
4503
- compact.set(sigCommitment);
4504
- compact.set(sigEncValue.subarray(0, 8), 32);
4505
- compact.set(sigEncAssetId.subarray(0, 4), 40);
4506
- compact.set(sigEncOwnerHash, 44);
4372
+ if (inputs.amount <= 0n) {
4373
+ throw new Error("Fee claim amount must be greater than zero.");
4374
+ }
4375
+ const circuitInputs = {
4376
+ commitment: inputs.commitment.toString(),
4377
+ value: inputs.amount.toString(),
4378
+ asset_id: inputs.assetId.toString(),
4379
+ owner_pubkey: inputs.ownerPubkey.toString(),
4380
+ blinding: inputs.blinding.toString()
4381
+ };
4382
+ const provider = options.provider ?? new WebArtifactProvider3();
4383
+ const opts = { provider };
4384
+ if (options.verbose !== void 0) opts.verbose = options.verbose;
4385
+ const proofResult = await generateProof3(CircuitType3.ValueProof, circuitInputs, opts);
4386
+ const [sigCommitment, sigValue, sigAssetId, sigOwnerHash] = proofResult.publicSignals.map(BigInt);
4387
+ const buf = new Uint8Array(76);
4388
+ buf.set(bigintTo32Le(sigCommitment), 0);
4389
+ buf.set(bigintTo32Le(sigValue).subarray(0, 8), 32);
4390
+ buf.set(bigintTo32Le(sigAssetId).subarray(0, 4), 40);
4391
+ buf.set(bigintTo32Le(sigOwnerHash), 44);
4507
4392
  return {
4508
- proof: result.proof,
4509
- publicSignals: Array.from(compact)
4393
+ proof: proofResult.proof,
4394
+ publicSignals: Array.from(buf)
4510
4395
  };
4511
4396
  }
4512
4397
 
@@ -4576,6 +4461,17 @@ function decodePrecompileCalldata(address, input) {
4576
4461
  return { fnSig, args: {} };
4577
4462
  }
4578
4463
  }
4464
+ if (fnSig.startsWith("claimShieldedFees(")) {
4465
+ try {
4466
+ const data = fromHex(input.slice(10));
4467
+ const commitment = toHex(data.slice(0, 32));
4468
+ const amount = decodeUint(data, 32);
4469
+ const assetId = decodeUint(data, 64);
4470
+ return { fnSig, args: { commitment, amount, assetId } };
4471
+ } catch {
4472
+ return { fnSig, args: {} };
4473
+ }
4474
+ }
4579
4475
  return { fnSig, args: {} };
4580
4476
  }
4581
4477
 
@@ -4583,8 +4479,8 @@ function decodePrecompileCalldata(address, input) {
4583
4479
  var CircuitId = {
4584
4480
  Transfer: 1,
4585
4481
  Unshield: 2,
4586
- Disclosure: 3,
4587
- PrivateLink: 4
4482
+ ValueProof: 4,
4483
+ PrivateLink: 5
4588
4484
  };
4589
4485
 
4590
4486
  // src/utils/string.ts
@@ -4773,39 +4669,6 @@ function mapExtrinsicArgs(section, method, args) {
4773
4669
  recipient: get(5, "recipient")
4774
4670
  };
4775
4671
  }
4776
- if (m_norm === "setauditpolicy") {
4777
- return {
4778
- auditors: get(0, "auditors"),
4779
- conditions: get(1, "conditions"),
4780
- max_frequency: get(2, "max_frequency"),
4781
- valid_until: get(3, "valid_until")
4782
- };
4783
- }
4784
- if (m_norm === "requestdisclosure") {
4785
- return {
4786
- target: get(0, "target"),
4787
- commitment: get(1, "commitment"),
4788
- required_fields: get(2, "required_fields"),
4789
- reason: get(3, "reason"),
4790
- auditor_bjj_pk_x: get(4, "auditor_bjj_pk_x"),
4791
- auditor_bjj_pk_y: get(5, "auditor_bjj_pk_y")
4792
- };
4793
- }
4794
- if (m_norm === "disclose") {
4795
- return {
4796
- commitment: get(0, "commitment"),
4797
- proof_bytes: get(1, "proof_bytes"),
4798
- public_signals: get(2, "public_signals"),
4799
- auditor: get(3, "auditor")
4800
- };
4801
- }
4802
- if (m_norm === "rejectdisclosure") {
4803
- return {
4804
- auditor: get(0, "auditor"),
4805
- commitment: get(1, "commitment"),
4806
- reason: get(2, "reason")
4807
- };
4808
- }
4809
4672
  if (m_norm === "registerasset") {
4810
4673
  return {
4811
4674
  name: get(0, "name"),
@@ -4820,19 +4683,6 @@ function mapExtrinsicArgs(section, method, args) {
4820
4683
  if (m_norm === "unverifyasset") {
4821
4684
  return { asset_id: get(0, "asset_id") };
4822
4685
  }
4823
- if (m_norm === "batchsubmitdisclosureproofs") {
4824
- return { submissions: get(0, "submissions") };
4825
- }
4826
- if (m_norm === "pruneexpiredrequest") {
4827
- return {
4828
- target: get(0, "target"),
4829
- auditor: get(1, "auditor"),
4830
- commitment: get(2, "commitment")
4831
- };
4832
- }
4833
- if (m_norm === "revokedisclosurerecord") {
4834
- return { commitment: get(0, "commitment") };
4835
- }
4836
4686
  }
4837
4687
  if (s === "ethereum" && m === "transact") {
4838
4688
  return { transaction: get(0, "transaction") };
@@ -5056,51 +4906,6 @@ function mapZkEventData(method, data) {
5056
4906
  };
5057
4907
  }
5058
4908
  const m_norm = m.replace(/_/g, "");
5059
- if (m_norm === "auditpolicyset") {
5060
- return {
5061
- account: get(0, "account"),
5062
- version: get(1, "version")
5063
- };
5064
- }
5065
- if (m_norm === "disclosed") {
5066
- return {
5067
- target: get(0, "target"),
5068
- auditor: get(1, "auditor"),
5069
- commitment: get(2, "commitment"),
5070
- signals: get(3, "signals")
5071
- };
5072
- }
5073
- if (m_norm === "disclosurerequested") {
5074
- return {
5075
- target: get(0, "target"),
5076
- auditor: get(1, "auditor"),
5077
- commitment: get(2, "commitment"),
5078
- required_fields: get(3, "required_fields"),
5079
- auditor_bjj_pk_x: get(4, "auditor_bjj_pk_x"),
5080
- auditor_bjj_pk_y: get(5, "auditor_bjj_pk_y")
5081
- };
5082
- }
5083
- if (m_norm === "disclosurerejected") {
5084
- return {
5085
- target: get(0, "target"),
5086
- auditor: get(1, "auditor"),
5087
- commitment: get(2, "commitment"),
5088
- reason: get(3, "reason")
5089
- };
5090
- }
5091
- if (m_norm === "disclosurerequestexpired") {
5092
- return {
5093
- target: get(0, "target"),
5094
- auditor: get(1, "auditor"),
5095
- commitment: get(2, "commitment")
5096
- };
5097
- }
5098
- if (m_norm === "disclosurerecordrevoked") {
5099
- return {
5100
- who: get(0, "who"),
5101
- commitment: get(1, "commitment")
5102
- };
5103
- }
5104
4909
  if (m_norm === "assetregistered") {
5105
4910
  return { asset_id: get(0, "asset_id") };
5106
4911
  }
@@ -5390,17 +5195,16 @@ export {
5390
5195
  bigintTo32Be,
5391
5196
  bigintTo32Le,
5392
5197
  bigintTo32LeArr,
5393
- buildDisclosurePublicSignals,
5394
5198
  buildDummyTransferInput,
5395
5199
  bytesToBigintLE,
5396
5200
  computeNullifier,
5397
5201
  computePathIndices,
5398
5202
  connectInjectedExtension,
5203
+ createNoteDisclosureKey,
5204
+ decodeNoteDisclosureKey,
5399
5205
  decodePrecompileCalldata,
5400
- decryptDisclosureSignals,
5401
5206
  decryptJson,
5402
5207
  decryptNoteRecord,
5403
- deriveBabyJubjubKeypair,
5404
5208
  deriveMasterKeyBytes,
5405
5209
  deriveOwnerPk,
5406
5210
  deriveSpendingKeyFromSignature,
@@ -5421,7 +5225,6 @@ export {
5421
5225
  formatORB,
5422
5226
  fromBase64,
5423
5227
  fromHex,
5424
- generateDisclosureProof,
5425
5228
  generateFeeClaimProof,
5426
5229
  generateTransferProof,
5427
5230
  generateUnshieldProof,