@orbinum/sdk 0.5.0 → 0.7.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/LICENSE +21 -0
- package/README.md +16 -499
- package/dist/index.d.mts +355 -739
- package/dist/index.d.ts +355 -739
- package/dist/index.js +239 -424
- package/dist/index.mjs +231 -414
- package/package.json +16 -16
package/dist/index.js
CHANGED
|
@@ -27,7 +27,7 @@ __export(index_exports, {
|
|
|
27
27
|
BN254_R: () => BN254_R,
|
|
28
28
|
Blake2256: () => import_substrate_bindings3.Blake2256,
|
|
29
29
|
CircuitId: () => CircuitId,
|
|
30
|
-
CircuitType: () =>
|
|
30
|
+
CircuitType: () => import_proof_generator.CircuitType,
|
|
31
31
|
CryptoPrecompiles: () => CryptoPrecompiles,
|
|
32
32
|
ENCRYPTED_MEMO_SIZE: () => ENCRYPTED_MEMO_SIZE,
|
|
33
33
|
EncryptedMemo: () => EncryptedMemo,
|
|
@@ -50,7 +50,7 @@ __export(index_exports, {
|
|
|
50
50
|
Storage: () => import_substrate_bindings3.Storage,
|
|
51
51
|
SubstrateClient: () => SubstrateClient,
|
|
52
52
|
VaultLockedError: () => VaultLockedError,
|
|
53
|
-
WebArtifactProvider: () =>
|
|
53
|
+
WebArtifactProvider: () => import_proof_generator.WebArtifactProvider,
|
|
54
54
|
ZkVerifierModule: () => ZkVerifierModule,
|
|
55
55
|
accountIdHexToSs58: () => accountIdHexToSs58,
|
|
56
56
|
addressToAccountIdHex: () => addressToAccountIdHex,
|
|
@@ -59,17 +59,16 @@ __export(index_exports, {
|
|
|
59
59
|
bigintTo32Be: () => bigintTo32Be,
|
|
60
60
|
bigintTo32Le: () => bigintTo32Le,
|
|
61
61
|
bigintTo32LeArr: () => bigintTo32LeArr,
|
|
62
|
-
buildDisclosurePublicSignals: () => buildDisclosurePublicSignals,
|
|
63
62
|
buildDummyTransferInput: () => buildDummyTransferInput,
|
|
64
63
|
bytesToBigintLE: () => bytesToBigintLE,
|
|
65
64
|
computeNullifier: () => computeNullifier,
|
|
66
65
|
computePathIndices: () => computePathIndices,
|
|
67
66
|
connectInjectedExtension: () => import_pjs_signer.connectInjectedExtension,
|
|
67
|
+
createNoteDisclosureKey: () => createNoteDisclosureKey,
|
|
68
|
+
decodeNoteDisclosureKey: () => decodeNoteDisclosureKey,
|
|
68
69
|
decodePrecompileCalldata: () => decodePrecompileCalldata,
|
|
69
|
-
decryptDisclosureSignals: () => decryptDisclosureSignals,
|
|
70
70
|
decryptJson: () => decryptJson,
|
|
71
71
|
decryptNoteRecord: () => decryptNoteRecord,
|
|
72
|
-
deriveBabyJubjubKeypair: () => deriveBabyJubjubKeypair,
|
|
73
72
|
deriveMasterKeyBytes: () => deriveMasterKeyBytes,
|
|
74
73
|
deriveOwnerPk: () => deriveOwnerPk,
|
|
75
74
|
deriveSpendingKeyFromSignature: () => deriveSpendingKeyFromSignature,
|
|
@@ -90,7 +89,6 @@ __export(index_exports, {
|
|
|
90
89
|
formatORB: () => formatORB,
|
|
91
90
|
fromBase64: () => fromBase64,
|
|
92
91
|
fromHex: () => fromHex,
|
|
93
|
-
generateDisclosureProof: () => import_proof_generator.generateDisclosureProof,
|
|
94
92
|
generateFeeClaimProof: () => generateFeeClaimProof,
|
|
95
93
|
generateTransferProof: () => generateTransferProof,
|
|
96
94
|
generateUnshieldProof: () => generateUnshieldProof,
|
|
@@ -132,7 +130,7 @@ module.exports = __toCommonJS(index_exports);
|
|
|
132
130
|
|
|
133
131
|
// src/substrate/SubstrateClient.ts
|
|
134
132
|
var import_polkadot_api = require("polkadot-api");
|
|
135
|
-
var
|
|
133
|
+
var import_ws = require("polkadot-api/ws");
|
|
136
134
|
var import_metadata_builders = require("@polkadot-api/metadata-builders");
|
|
137
135
|
var import_substrate_bindings = require("@polkadot-api/substrate-bindings");
|
|
138
136
|
var import_substrate_bindings2 = require("@polkadot-api/substrate-bindings");
|
|
@@ -178,7 +176,7 @@ var SubstrateClient = class _SubstrateClient {
|
|
|
178
176
|
* Throws if the node does not respond within `timeoutMs`.
|
|
179
177
|
*/
|
|
180
178
|
static async connect(wsUrl, timeoutMs = 15e3) {
|
|
181
|
-
const provider = (0,
|
|
179
|
+
const provider = (0, import_ws.getWsProvider)(wsUrl);
|
|
182
180
|
const papi = (0, import_polkadot_api.createClient)(provider);
|
|
183
181
|
await Promise.race([
|
|
184
182
|
papi._request("system_name", []),
|
|
@@ -355,20 +353,20 @@ var SubstrateClient = class _SubstrateClient {
|
|
|
355
353
|
* into a PAPI UnsafeTransaction that can be signed and submitted.
|
|
356
354
|
*/
|
|
357
355
|
async txFromCallData(callData) {
|
|
358
|
-
return this._papi.getUnsafeApi().txFromCallData(
|
|
356
|
+
return this._papi.getUnsafeApi().txFromCallData(callData);
|
|
359
357
|
}
|
|
360
358
|
/**
|
|
361
359
|
* Submits a pre-signed extrinsic (hex string) and waits for finalization.
|
|
362
360
|
*/
|
|
363
361
|
async submit(signedHex) {
|
|
364
|
-
return this._papi.submit(signedHex);
|
|
362
|
+
return this._papi.submit(import_polkadot_api.Binary.fromHex(signedHex));
|
|
365
363
|
}
|
|
366
364
|
/**
|
|
367
365
|
* Submits a pre-signed extrinsic and returns an Observable of tx lifecycle events.
|
|
368
366
|
* Events: TxSigned → TxBroadcasted → TxBestBlocksState → TxFinalized
|
|
369
367
|
*/
|
|
370
368
|
submitAndWatch(signedHex) {
|
|
371
|
-
return this._papi.submitAndWatch(signedHex);
|
|
369
|
+
return this._papi.submitAndWatch(import_polkadot_api.Binary.fromHex(signedHex));
|
|
372
370
|
}
|
|
373
371
|
/**
|
|
374
372
|
* Submits a bare (unsigned) extrinsic hex and waits for finalization.
|
|
@@ -376,7 +374,7 @@ var SubstrateClient = class _SubstrateClient {
|
|
|
376
374
|
* The bare tx hex is produced by `tx.getBareTx()` from polkadot-api.
|
|
377
375
|
*/
|
|
378
376
|
async submitUnsignedAndWatch(bareTxHex) {
|
|
379
|
-
return this._papi.submit(bareTxHex);
|
|
377
|
+
return this._papi.submit(import_polkadot_api.Binary.fromHex(bareTxHex));
|
|
380
378
|
}
|
|
381
379
|
/**
|
|
382
380
|
* Convenience: wrap raw call bytes and sign+submit in one step.
|
|
@@ -1319,6 +1317,46 @@ var IndexerClient = class {
|
|
|
1319
1317
|
`/shielded/address/${encodeURIComponent(address.toLowerCase())}${qs}`
|
|
1320
1318
|
);
|
|
1321
1319
|
}
|
|
1320
|
+
// ─── Relayers ──────────────────────────────────────────────────────────────
|
|
1321
|
+
/** Returns a paginated list of relayers. Filter by active status with `active`. */
|
|
1322
|
+
async getRelayers(params) {
|
|
1323
|
+
const qs = this.buildQuery({
|
|
1324
|
+
page: params?.page,
|
|
1325
|
+
limit: params?.limit,
|
|
1326
|
+
active: params?.active === void 0 ? void 0 : params.active ? "true" : "false"
|
|
1327
|
+
});
|
|
1328
|
+
return this.get(`/relayers${qs}`);
|
|
1329
|
+
}
|
|
1330
|
+
/** Returns a single relayer by EVM address, or null if not found. */
|
|
1331
|
+
async getRelayer(evmAddress) {
|
|
1332
|
+
return this.getOrNull(`/relayers/${encodeURIComponent(evmAddress.toLowerCase())}`);
|
|
1333
|
+
}
|
|
1334
|
+
/** Returns a paginated list of relay fee events. */
|
|
1335
|
+
async getRelayFees(params) {
|
|
1336
|
+
const qs = this.buildQuery({
|
|
1337
|
+
page: params?.page,
|
|
1338
|
+
limit: params?.limit,
|
|
1339
|
+
relayer: params?.relayer,
|
|
1340
|
+
type: params?.type
|
|
1341
|
+
});
|
|
1342
|
+
return this.get(`/relayers/fees${qs}`);
|
|
1343
|
+
}
|
|
1344
|
+
/** Returns aggregated relay fee balances per asset for a given relayer account. */
|
|
1345
|
+
async getRelayFeesSummary(relayer) {
|
|
1346
|
+
return this.get(
|
|
1347
|
+
`/relayers/fees/summary/${encodeURIComponent(relayer)}`
|
|
1348
|
+
);
|
|
1349
|
+
}
|
|
1350
|
+
// ─── Registered assets ─────────────────────────────────────────────────────
|
|
1351
|
+
/** Returns a paginated list of assets registered via register_asset. */
|
|
1352
|
+
async getRegisteredAssets(params) {
|
|
1353
|
+
const qs = this.buildQuery({ page: params?.page, limit: params?.limit });
|
|
1354
|
+
return this.get(`/shielded/assets${qs}`);
|
|
1355
|
+
}
|
|
1356
|
+
/** Returns a single registered asset by its ID, or null if not found. */
|
|
1357
|
+
async getRegisteredAsset(assetId) {
|
|
1358
|
+
return this.getOrNull(`/shielded/assets/${encodeURIComponent(assetId)}`);
|
|
1359
|
+
}
|
|
1322
1360
|
// ─── Stats & Health ────────────────────────────────────────────────────────
|
|
1323
1361
|
/** Returns aggregated indexer statistics. */
|
|
1324
1362
|
async getStats() {
|
|
@@ -1801,7 +1839,7 @@ var ShieldedPoolModule = class {
|
|
|
1801
1839
|
asset_id: params.assetId,
|
|
1802
1840
|
amount: params.amount,
|
|
1803
1841
|
commitment: import_polkadot_api2.Binary.fromHex(params.commitment),
|
|
1804
|
-
encrypted_memo:
|
|
1842
|
+
encrypted_memo: params.encryptedMemo
|
|
1805
1843
|
});
|
|
1806
1844
|
return toTxResult(
|
|
1807
1845
|
await (txOptions !== void 0 ? tx.signAndSubmit(signer, txOptions) : tx.signAndSubmit(signer))
|
|
@@ -1821,12 +1859,12 @@ var ShieldedPoolModule = class {
|
|
|
1821
1859
|
let changeEncryptedMemo;
|
|
1822
1860
|
if (params.changeEncryptedMemo && params.changeEncryptedMemo.length > 0) {
|
|
1823
1861
|
EncryptedMemo.validate(params.changeEncryptedMemo, "changeEncryptedMemo");
|
|
1824
|
-
changeEncryptedMemo =
|
|
1862
|
+
changeEncryptedMemo = params.changeEncryptedMemo;
|
|
1825
1863
|
} else {
|
|
1826
|
-
changeEncryptedMemo =
|
|
1864
|
+
changeEncryptedMemo = new Uint8Array(0);
|
|
1827
1865
|
}
|
|
1828
1866
|
const tx = callUnsafeTx(entry, {
|
|
1829
|
-
proof:
|
|
1867
|
+
proof: params.proof,
|
|
1830
1868
|
merkle_root: import_polkadot_api2.Binary.fromHex(params.merkleRoot),
|
|
1831
1869
|
nullifier: import_polkadot_api2.Binary.fromHex(params.nullifier),
|
|
1832
1870
|
asset_id: params.assetId,
|
|
@@ -1859,11 +1897,11 @@ var ShieldedPoolModule = class {
|
|
|
1859
1897
|
out.encryptedMemo,
|
|
1860
1898
|
`privateTransfer.outputs[${i}].encryptedMemo`
|
|
1861
1899
|
);
|
|
1862
|
-
return
|
|
1900
|
+
return out.encryptedMemo;
|
|
1863
1901
|
});
|
|
1864
1902
|
const entry = resolveTx(this.substrate.unsafe, "ShieldedPool", "private_transfer");
|
|
1865
1903
|
const tx = callUnsafeTx(entry, {
|
|
1866
|
-
proof:
|
|
1904
|
+
proof: params.proof,
|
|
1867
1905
|
merkle_root: import_polkadot_api2.Binary.fromHex(params.merkleRoot),
|
|
1868
1906
|
nullifiers,
|
|
1869
1907
|
commitments,
|
|
@@ -1891,7 +1929,7 @@ var ShieldedPoolModule = class {
|
|
|
1891
1929
|
assetId: item.assetId,
|
|
1892
1930
|
amount: item.amount.toString(),
|
|
1893
1931
|
commitment: import_polkadot_api2.Binary.fromHex(item.commitment),
|
|
1894
|
-
encryptedMemo:
|
|
1932
|
+
encryptedMemo: item.encryptedMemo
|
|
1895
1933
|
};
|
|
1896
1934
|
});
|
|
1897
1935
|
const entry = resolveTx(this.substrate.unsafe, "ShieldedPool", "shield_batch");
|
|
@@ -1903,7 +1941,7 @@ var ShieldedPoolModule = class {
|
|
|
1903
1941
|
/**
|
|
1904
1942
|
* Claims accrued relay fees into the shielded pool.
|
|
1905
1943
|
* This is a SIGNED transaction — the relayer must sign it with their wallet.
|
|
1906
|
-
* Before calling this, generate a ZK
|
|
1944
|
+
* Before calling this, generate a ZK value proof with generateFeeClaimProof() (not yet implemented).
|
|
1907
1945
|
*
|
|
1908
1946
|
* Extrinsic: shieldedPool.claim_shielded_fees(commitment, amount, asset_id, memo, proof, public_signals)
|
|
1909
1947
|
*/
|
|
@@ -1914,98 +1952,9 @@ var ShieldedPoolModule = class {
|
|
|
1914
1952
|
commitment: import_polkadot_api2.Binary.fromHex(params.commitment),
|
|
1915
1953
|
amount: params.amount,
|
|
1916
1954
|
asset_id: params.assetId,
|
|
1917
|
-
encrypted_memo:
|
|
1918
|
-
proof:
|
|
1919
|
-
public_signals:
|
|
1920
|
-
});
|
|
1921
|
-
return toTxResult(
|
|
1922
|
-
await (txOptions !== void 0 ? tx.signAndSubmit(signer, txOptions) : tx.signAndSubmit(signer))
|
|
1923
|
-
);
|
|
1924
|
-
}
|
|
1925
|
-
// ─── Selective Disclosure ──────────────────────────────────────────────────
|
|
1926
|
-
/**
|
|
1927
|
-
* Requests a selective disclosure from a target account for a specific commitment.
|
|
1928
|
-
* The auditor's Baby Jubjub public key is included so the note owner knows
|
|
1929
|
-
* which key to encrypt to when generating the proof.
|
|
1930
|
-
* Extrinsic: shieldedPool.request_disclosure(target, commitment, required_fields,
|
|
1931
|
-
* reason, auditor_bjj_pk_x, auditor_bjj_pk_y)
|
|
1932
|
-
*/
|
|
1933
|
-
async requestDisclosure(params, signer, txOptions) {
|
|
1934
|
-
const entry = resolveTx(this.substrate.unsafe, "ShieldedPool", "request_disclosure");
|
|
1935
|
-
const tx = callUnsafeTx(entry, {
|
|
1936
|
-
target: params.target,
|
|
1937
|
-
commitment: import_polkadot_api2.Binary.fromBytes(new Uint8Array(params.commitment)),
|
|
1938
|
-
required_fields: {
|
|
1939
|
-
value: params.requiredFields.value,
|
|
1940
|
-
asset_id: params.requiredFields.assetId,
|
|
1941
|
-
owner: params.requiredFields.owner
|
|
1942
|
-
},
|
|
1943
|
-
reason: import_polkadot_api2.Binary.fromText(params.reason),
|
|
1944
|
-
auditor_bjj_pk_x: import_polkadot_api2.Binary.fromBytes(new Uint8Array(params.auditorBjjPkX)),
|
|
1945
|
-
auditor_bjj_pk_y: import_polkadot_api2.Binary.fromBytes(new Uint8Array(params.auditorBjjPkY))
|
|
1946
|
-
});
|
|
1947
|
-
return toTxResult(
|
|
1948
|
-
await (txOptions !== void 0 ? tx.signAndSubmit(signer, txOptions) : tx.signAndSubmit(signer))
|
|
1949
|
-
);
|
|
1950
|
-
}
|
|
1951
|
-
/**
|
|
1952
|
-
* Submits a Groth16 ZK disclosure proof for a note commitment.
|
|
1953
|
-
* The proof reveals the selected fields (value, asset_id, owner_hash) on-chain.
|
|
1954
|
-
* Use generateDisclosureProof() + buildDisclosurePublicSignals() before calling this.
|
|
1955
|
-
* Extrinsic: shieldedPool.disclose(commitment, proof_bytes, public_signals, auditor)
|
|
1956
|
-
*/
|
|
1957
|
-
async disclose(params, signer, txOptions) {
|
|
1958
|
-
const entry = resolveTx(this.substrate.unsafe, "ShieldedPool", "disclose");
|
|
1959
|
-
const tx = callUnsafeTx(entry, {
|
|
1960
|
-
commitment: import_polkadot_api2.Binary.fromBytes(new Uint8Array(params.commitment)),
|
|
1961
|
-
proof_bytes: import_polkadot_api2.Binary.fromBytes(new Uint8Array(params.proofBytes)),
|
|
1962
|
-
public_signals: import_polkadot_api2.Binary.fromBytes(new Uint8Array(params.publicSignals)),
|
|
1963
|
-
auditor: params.auditor
|
|
1964
|
-
});
|
|
1965
|
-
return toTxResult(
|
|
1966
|
-
await (txOptions !== void 0 ? tx.signAndSubmit(signer, txOptions) : tx.signAndSubmit(signer))
|
|
1967
|
-
);
|
|
1968
|
-
}
|
|
1969
|
-
/**
|
|
1970
|
-
* Rejects a pending disclosure request from an auditor for a specific commitment.
|
|
1971
|
-
* Extrinsic: shieldedPool.reject_disclosure(auditor, commitment, reason)
|
|
1972
|
-
*/
|
|
1973
|
-
async rejectDisclosure(params, signer, txOptions) {
|
|
1974
|
-
const entry = resolveTx(this.substrate.unsafe, "ShieldedPool", "reject_disclosure");
|
|
1975
|
-
const tx = callUnsafeTx(entry, {
|
|
1976
|
-
auditor: params.auditor,
|
|
1977
|
-
commitment: import_polkadot_api2.Binary.fromBytes(new Uint8Array(params.commitment)),
|
|
1978
|
-
reason: import_polkadot_api2.Binary.fromText(params.reason)
|
|
1979
|
-
});
|
|
1980
|
-
return toTxResult(
|
|
1981
|
-
await (txOptions !== void 0 ? tx.signAndSubmit(signer, txOptions) : tx.signAndSubmit(signer))
|
|
1982
|
-
);
|
|
1983
|
-
}
|
|
1984
|
-
/**
|
|
1985
|
-
* Cleans up a disclosure request that has passed its expiration block.
|
|
1986
|
-
* Permissionless — any account can prune expired requests.
|
|
1987
|
-
* Extrinsic: shieldedPool.prune_expired_request(target, auditor, commitment)
|
|
1988
|
-
*/
|
|
1989
|
-
async pruneExpiredRequest(params, signer, txOptions) {
|
|
1990
|
-
const entry = resolveTx(this.substrate.unsafe, "ShieldedPool", "prune_expired_request");
|
|
1991
|
-
const tx = callUnsafeTx(entry, {
|
|
1992
|
-
target: params.target,
|
|
1993
|
-
auditor: params.auditor,
|
|
1994
|
-
commitment: import_polkadot_api2.Binary.fromBytes(new Uint8Array(params.commitment))
|
|
1995
|
-
});
|
|
1996
|
-
return toTxResult(
|
|
1997
|
-
await (txOptions !== void 0 ? tx.signAndSubmit(signer, txOptions) : tx.signAndSubmit(signer))
|
|
1998
|
-
);
|
|
1999
|
-
}
|
|
2000
|
-
/**
|
|
2001
|
-
* Revokes a previously submitted voluntary disclosure record.
|
|
2002
|
-
* Only applies to self-disclosures (auditor = None). Auditor-requested records are permanent.
|
|
2003
|
-
* Extrinsic: shieldedPool.revoke_disclosure_record(commitment)
|
|
2004
|
-
*/
|
|
2005
|
-
async revokeDisclosureRecord(params, signer, txOptions) {
|
|
2006
|
-
const entry = resolveTx(this.substrate.unsafe, "ShieldedPool", "revoke_disclosure_record");
|
|
2007
|
-
const tx = callUnsafeTx(entry, {
|
|
2008
|
-
commitment: import_polkadot_api2.Binary.fromBytes(new Uint8Array(params.commitment))
|
|
1955
|
+
encrypted_memo: params.encryptedMemo,
|
|
1956
|
+
proof: params.proof,
|
|
1957
|
+
public_signals: params.publicSignals
|
|
2009
1958
|
});
|
|
2010
1959
|
return toTxResult(
|
|
2011
1960
|
await (txOptions !== void 0 ? tx.signAndSubmit(signer, txOptions) : tx.signAndSubmit(signer))
|
|
@@ -2317,12 +2266,7 @@ var AccountMappingModule = class {
|
|
|
2317
2266
|
*/
|
|
2318
2267
|
async addChainLink(params, signer) {
|
|
2319
2268
|
const entry = resolveTx(this.substrate.unsafe, "accountMapping", "addChainLink");
|
|
2320
|
-
const tx = callUnsafeTx(
|
|
2321
|
-
entry,
|
|
2322
|
-
params.chainId,
|
|
2323
|
-
import_polkadot_api3.Binary.fromBytes(params.address),
|
|
2324
|
-
import_polkadot_api3.Binary.fromBytes(params.signature)
|
|
2325
|
-
);
|
|
2269
|
+
const tx = callUnsafeTx(entry, params.chainId, params.address, params.signature);
|
|
2326
2270
|
return toTxResult(await tx.signAndSubmit(signer));
|
|
2327
2271
|
}
|
|
2328
2272
|
/**
|
|
@@ -2393,14 +2337,30 @@ var AccountMappingModule = class {
|
|
|
2393
2337
|
entry,
|
|
2394
2338
|
params.owner,
|
|
2395
2339
|
params.chainId,
|
|
2396
|
-
|
|
2397
|
-
|
|
2398
|
-
|
|
2340
|
+
params.address,
|
|
2341
|
+
params.signature,
|
|
2342
|
+
params.callData
|
|
2399
2343
|
);
|
|
2400
2344
|
return toTxResult(await tx.signAndSubmit(signer));
|
|
2401
2345
|
}
|
|
2402
2346
|
};
|
|
2403
2347
|
|
|
2348
|
+
// src/rpc-v2/ChainModule.ts
|
|
2349
|
+
var ChainModule = class {
|
|
2350
|
+
constructor(substrate) {
|
|
2351
|
+
this.substrate = substrate;
|
|
2352
|
+
}
|
|
2353
|
+
substrate;
|
|
2354
|
+
/**
|
|
2355
|
+
* Returns `true` if the given SS58 account is an active Aura validator.
|
|
2356
|
+
*
|
|
2357
|
+
* Reads `pallet_aura::Authorities` directly from storage at the best known block.
|
|
2358
|
+
*/
|
|
2359
|
+
async isValidator(ss58Address) {
|
|
2360
|
+
return this.substrate.request("chain_isValidator", [ss58Address]);
|
|
2361
|
+
}
|
|
2362
|
+
};
|
|
2363
|
+
|
|
2404
2364
|
// src/rpc-v2/helpers.ts
|
|
2405
2365
|
function mapAssetBalance(balance) {
|
|
2406
2366
|
return {
|
|
@@ -2761,14 +2721,8 @@ var SP_SEL = {
|
|
|
2761
2721
|
PRIVATE_TRANSFER: new Uint8Array([140, 15, 93, 36]),
|
|
2762
2722
|
// unshield(bytes,bytes32,bytes32,uint32,uint256,bytes32,uint256,bytes32) → 0xd21d9a79
|
|
2763
2723
|
UNSHIELD: new Uint8Array([210, 29, 154, 121]),
|
|
2764
|
-
//
|
|
2765
|
-
|
|
2766
|
-
// disclose(bytes32,bytes,bytes,bytes32) → 0xea8a4165 (caller = note owner)
|
|
2767
|
-
DISCLOSE: new Uint8Array([234, 138, 65, 101]),
|
|
2768
|
-
// rejectDisclosure(bytes32,bytes32,bytes) → 0x72b895a9 (caller = target)
|
|
2769
|
-
REJECT_DISCLOSURE: new Uint8Array([114, 184, 149, 169]),
|
|
2770
|
-
// pruneExpiredRequest(bytes32,bytes32,bytes32) → 0x0c338dcf (permissionless)
|
|
2771
|
-
PRUNE_EXPIRED_REQUEST: new Uint8Array([12, 51, 141, 207])
|
|
2724
|
+
// claimShieldedFees(bytes32,uint256,uint32,bytes,bytes,bytes) → 0x42e1e74c
|
|
2725
|
+
CLAIM_SHIELDED_FEES: new Uint8Array([66, 225, 231, 76])
|
|
2772
2726
|
};
|
|
2773
2727
|
var KNOWN_PRECOMPILES = {
|
|
2774
2728
|
// ── Ethereum standard (EIP) ─────────────────────────────────────────────
|
|
@@ -2814,10 +2768,7 @@ var KNOWN_PRECOMPILES = {
|
|
|
2814
2768
|
"9feb22ea": "shield(uint32,bytes32,bytes)",
|
|
2815
2769
|
"8c0f5d24": "privateTransfer(bytes,bytes32,bytes32[],bytes32[],bytes[],uint32,uint256)",
|
|
2816
2770
|
d21d9a79: "unshield(bytes,bytes32,bytes32,uint32,uint256,bytes32,uint256,bytes32)",
|
|
2817
|
-
|
|
2818
|
-
ea8a4165: "disclose(bytes32,bytes,bytes,bytes32)",
|
|
2819
|
-
"72b895a9": "rejectDisclosure(bytes32,bytes32,bytes)",
|
|
2820
|
-
"0c338dcf": "pruneExpiredRequest(bytes32,bytes32,bytes32)"
|
|
2771
|
+
"42e1e74c": "claimShieldedFees(bytes32,uint256,uint32,bytes,bytes,bytes)"
|
|
2821
2772
|
}
|
|
2822
2773
|
}
|
|
2823
2774
|
};
|
|
@@ -2980,132 +2931,77 @@ var ShieldedPoolPrecompile = class {
|
|
|
2980
2931
|
data: this.buildUnshieldCalldata(params)
|
|
2981
2932
|
});
|
|
2982
2933
|
}
|
|
2983
|
-
// ───
|
|
2934
|
+
// ─── claimShieldedFees ───────────────────────────────────────────────────────────────────
|
|
2984
2935
|
/**
|
|
2985
2936
|
* Returns the ABI-encoded calldata for
|
|
2986
|
-
* `
|
|
2937
|
+
* `claimShieldedFees(bytes32,uint256,uint32,bytes,bytes,bytes)`.
|
|
2987
2938
|
*
|
|
2988
|
-
*
|
|
2989
|
-
*
|
|
2990
|
-
|
|
2991
|
-
|
|
2992
|
-
|
|
2993
|
-
|
|
2994
|
-
|
|
2995
|
-
throw new RangeError("requestDisclosure: auditorBjjPkY must be 32 bytes");
|
|
2996
|
-
const target = fromHex(params.target);
|
|
2997
|
-
const commitment = fromHex(params.commitment);
|
|
2998
|
-
const reasonBytes = new TextEncoder().encode(params.reason);
|
|
2999
|
-
return encodeHex(
|
|
3000
|
-
SP_SEL.REQUEST_DISCLOSURE,
|
|
3001
|
-
{ type: "bytes32", value: target },
|
|
3002
|
-
{ type: "bytes32", value: commitment },
|
|
3003
|
-
{ type: "bool", value: params.disclosedValue },
|
|
3004
|
-
{ type: "bool", value: params.disclosedAssetId },
|
|
3005
|
-
{ type: "bool", value: params.disclosedOwner },
|
|
3006
|
-
{ type: "bytes", value: reasonBytes },
|
|
3007
|
-
{ type: "bytes32", value: params.auditorBjjPkX },
|
|
3008
|
-
{ type: "bytes32", value: params.auditorBjjPkY }
|
|
3009
|
-
);
|
|
3010
|
-
}
|
|
3011
|
-
/**
|
|
3012
|
-
* Requests selective disclosure of a specific commitment.
|
|
3013
|
-
*
|
|
3014
|
-
* The EVM caller is recorded as the auditor on-chain. The note owner can
|
|
3015
|
-
* respond with `disclose()` or reject with `rejectDisclosure()`.
|
|
2939
|
+
* ABI layout (params after selector):
|
|
2940
|
+
* - `commitment` — bytes32 (fixed)
|
|
2941
|
+
* - `amount` — uint256 (fixed)
|
|
2942
|
+
* - `asset_id` — uint32 (fixed, right-aligned)
|
|
2943
|
+
* - `memo` — bytes (dynamic)
|
|
2944
|
+
* - `proof` — bytes (dynamic, 128 bytes Groth16)
|
|
2945
|
+
* - `publicSignals` — bytes (dynamic, 76 bytes)
|
|
3016
2946
|
*
|
|
3017
|
-
*
|
|
2947
|
+
* The validator identity is derived from `msg.sender` in the precompile —
|
|
2948
|
+
* do NOT include it in the calldata.
|
|
3018
2949
|
*/
|
|
3019
|
-
|
|
3020
|
-
|
|
3021
|
-
|
|
3022
|
-
|
|
3023
|
-
/**
|
|
3024
|
-
* Returns the ABI-encoded calldata for `disclose(bytes32,bytes,bytes,bytes32)`.
|
|
3025
|
-
*
|
|
3026
|
-
* The **EVM caller** is treated as the **note owner** on-chain.
|
|
3027
|
-
* `params.proofBytes` must be exactly 128 bytes; `params.publicSignals` exactly 256 bytes.
|
|
3028
|
-
*/
|
|
3029
|
-
buildDiscloseCalldata(params) {
|
|
3030
|
-
if (params.proofBytes.length !== 128)
|
|
3031
|
-
throw new RangeError("disclose: proofBytes must be exactly 128 bytes");
|
|
3032
|
-
if (params.publicSignals.length !== 256)
|
|
3033
|
-
throw new RangeError("disclose: publicSignals must be exactly 256 bytes");
|
|
3034
|
-
const commitment = fromHex(params.commitment);
|
|
3035
|
-
const auditor = fromHex(params.auditor);
|
|
3036
|
-
return encodeHex(
|
|
3037
|
-
SP_SEL.DISCLOSE,
|
|
3038
|
-
{ type: "bytes32", value: commitment },
|
|
3039
|
-
{ type: "bytes", value: params.proofBytes },
|
|
3040
|
-
{ type: "bytes", value: params.publicSignals },
|
|
3041
|
-
{ type: "bytes32", value: auditor }
|
|
2950
|
+
buildClaimShieldedFeesCalldata(params) {
|
|
2951
|
+
EncryptedMemo.validate(
|
|
2952
|
+
params.encryptedMemo,
|
|
2953
|
+
"buildClaimShieldedFeesCalldata.encryptedMemo"
|
|
3042
2954
|
);
|
|
3043
|
-
|
|
3044
|
-
|
|
3045
|
-
|
|
3046
|
-
|
|
3047
|
-
|
|
3048
|
-
|
|
3049
|
-
|
|
3050
|
-
|
|
3051
|
-
* Extrinsic: `shieldedPool.disclose(commitment, proofBytes, publicSignals, auditor)`
|
|
3052
|
-
*/
|
|
3053
|
-
async disclose(params, signer) {
|
|
3054
|
-
return signer({ to: this.addr, data: this.buildDiscloseCalldata(params) });
|
|
3055
|
-
}
|
|
3056
|
-
// ─── rejectDisclosure ──────────────────────────────────────────────────────
|
|
3057
|
-
/**
|
|
3058
|
-
* Returns the ABI-encoded calldata for `rejectDisclosure(bytes32,bytes32,bytes)`.
|
|
3059
|
-
*
|
|
3060
|
-
* The **EVM caller** is treated as the **target** (note owner) on-chain.
|
|
3061
|
-
*/
|
|
3062
|
-
buildRejectDisclosureCalldata(params) {
|
|
3063
|
-
const auditor = fromHex(params.auditor);
|
|
2955
|
+
if (params.proof.length === 0) {
|
|
2956
|
+
throw new Error("claimShieldedFees: proof must not be empty");
|
|
2957
|
+
}
|
|
2958
|
+
if (params.publicSignals.length !== 76) {
|
|
2959
|
+
throw new Error(
|
|
2960
|
+
`claimShieldedFees: publicSignals must be 76 bytes, got ${params.publicSignals.length}`
|
|
2961
|
+
);
|
|
2962
|
+
}
|
|
3064
2963
|
const commitment = fromHex(params.commitment);
|
|
3065
|
-
const reasonBytes = new TextEncoder().encode(params.reason);
|
|
3066
2964
|
return encodeHex(
|
|
3067
|
-
SP_SEL.
|
|
3068
|
-
{ type: "bytes32", value: auditor },
|
|
2965
|
+
SP_SEL.CLAIM_SHIELDED_FEES,
|
|
3069
2966
|
{ type: "bytes32", value: commitment },
|
|
3070
|
-
{ type: "
|
|
2967
|
+
{ type: "uint", value: params.amount },
|
|
2968
|
+
{ type: "uint", value: BigInt(params.assetId) },
|
|
2969
|
+
{ type: "bytes", value: params.encryptedMemo },
|
|
2970
|
+
{ type: "bytes", value: params.proof },
|
|
2971
|
+
{ type: "bytes", value: params.publicSignals }
|
|
3071
2972
|
);
|
|
3072
2973
|
}
|
|
3073
2974
|
/**
|
|
3074
|
-
*
|
|
2975
|
+
* Claims accumulated relay fees as a private shielded note.
|
|
3075
2976
|
*
|
|
3076
|
-
*
|
|
2977
|
+
* This extrinsic is for **validators/relayers** who have accrued fees in
|
|
2978
|
+
* `pallet-relayer` and want to receive them privately inside the shielded pool
|
|
2979
|
+
* instead of as a public balance credit.
|
|
3077
2980
|
*
|
|
3078
|
-
*
|
|
3079
|
-
|
|
3080
|
-
|
|
3081
|
-
return signer({ to: this.addr, data: this.buildRejectDisclosureCalldata(params) });
|
|
3082
|
-
}
|
|
3083
|
-
// ─── pruneExpiredRequest ───────────────────────────────────────────────────
|
|
3084
|
-
/**
|
|
3085
|
-
* Returns the ABI-encoded calldata for `pruneExpiredRequest(bytes32,bytes32,bytes32)`.
|
|
2981
|
+
* The ZK `value_proof` binds `commitment` to `(amount, assetId, ownerPk, blinding)`
|
|
2982
|
+
* so the runtime can verify the note encodes exactly the claimed fee amount,
|
|
2983
|
+
* preventing a malicious relayer from inflating the withdrawal.
|
|
3086
2984
|
*
|
|
3087
|
-
*
|
|
2985
|
+
* The `msg.sender` EVM address is used as the validator identity; it must match
|
|
2986
|
+
* the address that has pending relay fees in `pallet-relayer`.
|
|
2987
|
+
*
|
|
2988
|
+
* Extrinsic: `shieldedPool.claim_shielded_fees(commitment, amount, assetId, memo, proof, publicSignals)`
|
|
3088
2989
|
*/
|
|
3089
|
-
|
|
3090
|
-
|
|
3091
|
-
|
|
3092
|
-
|
|
3093
|
-
|
|
3094
|
-
SP_SEL.PRUNE_EXPIRED_REQUEST,
|
|
3095
|
-
{ type: "bytes32", value: target },
|
|
3096
|
-
{ type: "bytes32", value: auditor },
|
|
3097
|
-
{ type: "bytes32", value: commitment }
|
|
3098
|
-
);
|
|
2990
|
+
async claimShieldedFees(params, signer) {
|
|
2991
|
+
return signer({
|
|
2992
|
+
to: this.addr,
|
|
2993
|
+
data: this.buildClaimShieldedFeesCalldata(params)
|
|
2994
|
+
});
|
|
3099
2995
|
}
|
|
3100
2996
|
/**
|
|
3101
|
-
*
|
|
3102
|
-
*
|
|
3103
|
-
* Permissionless: any EVM account can call this once `expires_at` has passed.
|
|
3104
|
-
*
|
|
3105
|
-
* Extrinsic: `shieldedPool.pruneExpiredRequest(target, auditor, commitment)`
|
|
2997
|
+
* Estimates the EVM gas for a `claimShieldedFees` call.
|
|
3106
2998
|
*/
|
|
3107
|
-
async
|
|
3108
|
-
return
|
|
2999
|
+
async estimateClaimShieldedFeesGas(params, from) {
|
|
3000
|
+
return this.evm.estimateGas({
|
|
3001
|
+
from,
|
|
3002
|
+
to: this.addr,
|
|
3003
|
+
data: this.buildClaimShieldedFeesCalldata(params)
|
|
3004
|
+
});
|
|
3109
3005
|
}
|
|
3110
3006
|
};
|
|
3111
3007
|
|
|
@@ -3506,6 +3402,8 @@ var OrbinumClient = class _OrbinumClient {
|
|
|
3506
3402
|
accountMapping;
|
|
3507
3403
|
/** Typed access to `privacy_*` custom RPC endpoints. */
|
|
3508
3404
|
privacy;
|
|
3405
|
+
/** Typed access to general chain state via `chain_*` custom RPC endpoints. */
|
|
3406
|
+
chain;
|
|
3509
3407
|
/** Typed access to `zkVerifier_*` custom RPC endpoints. */
|
|
3510
3408
|
zkVerifier;
|
|
3511
3409
|
/** Typed access to `relayer_*` RPC endpoints (registry lookup and pending fee queries). */
|
|
@@ -3524,6 +3422,7 @@ var OrbinumClient = class _OrbinumClient {
|
|
|
3524
3422
|
this.shieldedPool = new ShieldedPoolModule(substrate);
|
|
3525
3423
|
this.accountMapping = new AccountMappingModule(substrate);
|
|
3526
3424
|
this.privacy = new PrivacyModule(substrate);
|
|
3425
|
+
this.chain = new ChainModule(substrate);
|
|
3527
3426
|
this.zkVerifier = new ZkVerifierModule(substrate);
|
|
3528
3427
|
this.relayerStatus = new RelayerStatusModule(substrate);
|
|
3529
3428
|
this.precompiles = evm ? {
|
|
@@ -4114,6 +4013,56 @@ function tryDecryptNoteVerbose(commitment, viewingSecretKey, spendingKey, ownOwn
|
|
|
4114
4013
|
};
|
|
4115
4014
|
}
|
|
4116
4015
|
|
|
4016
|
+
// src/shielded-pool/protocol/NoteDisclosure.ts
|
|
4017
|
+
var import_poseidon_lite3 = require("poseidon-lite");
|
|
4018
|
+
var PREFIX = "orbdisc:";
|
|
4019
|
+
var VERSION = 1;
|
|
4020
|
+
function toHex2(n) {
|
|
4021
|
+
return "0x" + n.toString(16);
|
|
4022
|
+
}
|
|
4023
|
+
function fromHex2(s) {
|
|
4024
|
+
return BigInt(s);
|
|
4025
|
+
}
|
|
4026
|
+
function createNoteDisclosureKey(note) {
|
|
4027
|
+
const payload = {
|
|
4028
|
+
v: VERSION,
|
|
4029
|
+
c: toHex2(note.commitment),
|
|
4030
|
+
val: toHex2(note.value),
|
|
4031
|
+
aid: toHex2(note.assetId),
|
|
4032
|
+
opk: toHex2(note.ownerPk),
|
|
4033
|
+
bld: toHex2(note.blinding)
|
|
4034
|
+
};
|
|
4035
|
+
const json = JSON.stringify(payload);
|
|
4036
|
+
const b64 = btoa(json).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
|
|
4037
|
+
return PREFIX + b64;
|
|
4038
|
+
}
|
|
4039
|
+
function decodeNoteDisclosureKey(key) {
|
|
4040
|
+
try {
|
|
4041
|
+
if (!key.startsWith(PREFIX)) return null;
|
|
4042
|
+
const b64 = key.slice(PREFIX.length).replace(/-/g, "+").replace(/_/g, "/");
|
|
4043
|
+
const json = atob(b64);
|
|
4044
|
+
const payload = JSON.parse(json);
|
|
4045
|
+
if (payload.v !== VERSION) return null;
|
|
4046
|
+
const disclosure = {
|
|
4047
|
+
commitment: fromHex2(payload.c),
|
|
4048
|
+
value: fromHex2(payload.val),
|
|
4049
|
+
assetId: fromHex2(payload.aid),
|
|
4050
|
+
ownerPk: fromHex2(payload.opk),
|
|
4051
|
+
blinding: fromHex2(payload.bld)
|
|
4052
|
+
};
|
|
4053
|
+
const recomputed = (0, import_poseidon_lite3.poseidon4)([
|
|
4054
|
+
disclosure.value,
|
|
4055
|
+
disclosure.assetId,
|
|
4056
|
+
disclosure.ownerPk,
|
|
4057
|
+
disclosure.blinding
|
|
4058
|
+
]);
|
|
4059
|
+
if (recomputed !== disclosure.commitment) return null;
|
|
4060
|
+
return disclosure;
|
|
4061
|
+
} catch {
|
|
4062
|
+
return null;
|
|
4063
|
+
}
|
|
4064
|
+
}
|
|
4065
|
+
|
|
4117
4066
|
// src/shielded-pool/protocol/coinSelection.ts
|
|
4118
4067
|
var TRANSFER_TREE_DEPTH = 20;
|
|
4119
4068
|
function selectNotes(notes, needed) {
|
|
@@ -4150,49 +4099,6 @@ function buildDummyTransferInput(assetId) {
|
|
|
4150
4099
|
};
|
|
4151
4100
|
}
|
|
4152
4101
|
|
|
4153
|
-
// src/shielded-pool/protocol/disclosure.ts
|
|
4154
|
-
var import_proof_generator = require("@orbinum/proof-generator");
|
|
4155
|
-
var import_baby_jubjub5 = require("@zk-kit/baby-jubjub");
|
|
4156
|
-
var import_poseidon_lite3 = require("poseidon-lite");
|
|
4157
|
-
function hexFieldToBytes32(hex) {
|
|
4158
|
-
const clean = hex.startsWith("0x") || hex.startsWith("0X") ? hex.slice(2) : hex;
|
|
4159
|
-
return fromHex(clean.padStart(64, "0"));
|
|
4160
|
-
}
|
|
4161
|
-
function deriveBabyJubjubKeypair(substrateSigningKey) {
|
|
4162
|
-
let keyBigInt = 0n;
|
|
4163
|
-
for (let i = 0; i < substrateSigningKey.length; i++) {
|
|
4164
|
-
keyBigInt = keyBigInt << 8n | BigInt(substrateSigningKey[i]);
|
|
4165
|
-
}
|
|
4166
|
-
const sk = (0, import_poseidon_lite3.poseidon1)([keyBigInt]);
|
|
4167
|
-
const pk = (0, import_baby_jubjub5.mulPointEscalar)(import_baby_jubjub5.Base8, sk);
|
|
4168
|
-
return { sk, pkX: pk[0], pkY: pk[1] };
|
|
4169
|
-
}
|
|
4170
|
-
function buildDisclosurePublicSignals(commitment, auditorPkX, auditorPkY, proofOutput) {
|
|
4171
|
-
const buf = new Uint8Array(256);
|
|
4172
|
-
buf.set(hexFieldToBytes32(commitment), 0);
|
|
4173
|
-
buf.set(bigintTo32Le(auditorPkX), 32);
|
|
4174
|
-
buf.set(bigintTo32Le(auditorPkY), 64);
|
|
4175
|
-
buf.set(hexFieldToBytes32(proofOutput.encryptedData.epkX), 96);
|
|
4176
|
-
buf.set(hexFieldToBytes32(proofOutput.encryptedData.epkY), 128);
|
|
4177
|
-
buf.set(hexFieldToBytes32(proofOutput.encryptedData.encValue), 160);
|
|
4178
|
-
buf.set(hexFieldToBytes32(proofOutput.encryptedData.encAssetId), 192);
|
|
4179
|
-
buf.set(hexFieldToBytes32(proofOutput.encryptedData.encOwnerHash), 224);
|
|
4180
|
-
return Array.from(buf);
|
|
4181
|
-
}
|
|
4182
|
-
function decryptDisclosureSignals(auditorBjjSk, enc) {
|
|
4183
|
-
const shared = (0, import_baby_jubjub5.mulPointEscalar)([enc.epkX, enc.epkY], auditorBjjSk);
|
|
4184
|
-
const sharedX = shared[0];
|
|
4185
|
-
const sharedY = shared[1];
|
|
4186
|
-
const k0 = (0, import_poseidon_lite3.poseidon3)([sharedX, sharedY, 0n]);
|
|
4187
|
-
const k1 = (0, import_poseidon_lite3.poseidon3)([sharedX, sharedY, 1n]);
|
|
4188
|
-
const k2 = (0, import_poseidon_lite3.poseidon3)([sharedX, sharedY, 2n]);
|
|
4189
|
-
return {
|
|
4190
|
-
value: (enc.encValue - k0 + BN254_R) % BN254_R,
|
|
4191
|
-
assetId: (enc.encAssetId - k1 + BN254_R) % BN254_R,
|
|
4192
|
-
ownerHash: (enc.encOwnerHash - k2 + BN254_R) % BN254_R
|
|
4193
|
-
};
|
|
4194
|
-
}
|
|
4195
|
-
|
|
4196
4102
|
// src/utils/blinding.ts
|
|
4197
4103
|
function randomBlinding() {
|
|
4198
4104
|
const buf = new Uint8Array(32);
|
|
@@ -4204,7 +4110,7 @@ function randomBlinding() {
|
|
|
4204
4110
|
// src/privacy-keys/PrivacyKeys.ts
|
|
4205
4111
|
var import_hkdf2 = require("@noble/hashes/hkdf.js");
|
|
4206
4112
|
var import_sha23 = require("@noble/hashes/sha2.js");
|
|
4207
|
-
var
|
|
4113
|
+
var import_baby_jubjub5 = require("@zk-kit/baby-jubjub");
|
|
4208
4114
|
var IVK_DOMAIN = new TextEncoder().encode("orbinum-ivk-v1");
|
|
4209
4115
|
function deriveSpendingKeyMessage(chainId, address) {
|
|
4210
4116
|
return `orbinum-spending-key-v1
|
|
@@ -4227,13 +4133,13 @@ function deriveViewingSecretKey(spendingKey) {
|
|
|
4227
4133
|
}
|
|
4228
4134
|
function deriveViewingPublicKey(ivsk) {
|
|
4229
4135
|
const ivskScalar = BigInt(toHex(ivsk)) % BABYJUB_SUBORDER || 1n;
|
|
4230
|
-
const ivkPoint = (0,
|
|
4231
|
-
const packed = (0,
|
|
4136
|
+
const ivkPoint = (0, import_baby_jubjub5.mulPointEscalar)(import_baby_jubjub5.Base8, ivskScalar);
|
|
4137
|
+
const packed = (0, import_baby_jubjub5.packPoint)(ivkPoint);
|
|
4232
4138
|
return bigintTo32Le(packed);
|
|
4233
4139
|
}
|
|
4234
4140
|
function deriveOwnerPk(spendingKey) {
|
|
4235
4141
|
try {
|
|
4236
|
-
const pubPoint = (0,
|
|
4142
|
+
const pubPoint = (0, import_baby_jubjub5.mulPointEscalar)(import_baby_jubjub5.Base8, spendingKey);
|
|
4237
4143
|
return pubPoint[0];
|
|
4238
4144
|
} catch {
|
|
4239
4145
|
return 0n;
|
|
@@ -4504,9 +4410,9 @@ async function decryptNoteRecord(key, rec) {
|
|
|
4504
4410
|
}
|
|
4505
4411
|
|
|
4506
4412
|
// src/proof-generator/unshield.ts
|
|
4507
|
-
var
|
|
4413
|
+
var import_proof_generator = require("@orbinum/proof-generator");
|
|
4508
4414
|
var import_utils3 = require("@noble/ciphers/utils.js");
|
|
4509
|
-
var
|
|
4415
|
+
var import_baby_jubjub6 = require("@zk-kit/baby-jubjub");
|
|
4510
4416
|
var import_poseidon_lite4 = require("poseidon-lite");
|
|
4511
4417
|
|
|
4512
4418
|
// src/proof-generator/merkle.ts
|
|
@@ -4529,7 +4435,7 @@ async function generateUnshieldProof(inputs, options = {}) {
|
|
|
4529
4435
|
if (changeValue < 0n) {
|
|
4530
4436
|
throw new Error("changeValue must be >= 0.");
|
|
4531
4437
|
}
|
|
4532
|
-
const changeOwnerPubkey = inputs.changeOwnerPubkey ?? (0,
|
|
4438
|
+
const changeOwnerPubkey = inputs.changeOwnerPubkey ?? (0, import_baby_jubjub6.mulPointEscalar)(import_baby_jubjub6.Base8, inputs.spendingKey)[0];
|
|
4533
4439
|
const changeBlinding = inputs.changeBlinding ?? (changeValue > 0n ? bytesToBigintLE((0, import_utils3.randomBytes)(32)) : 0n);
|
|
4534
4440
|
const changeCommitment = changeValue > 0n ? (0, import_poseidon_lite4.poseidon4)([changeValue, inputs.assetId, changeOwnerPubkey, changeBlinding]) : 0n;
|
|
4535
4441
|
const circuitInputs = {
|
|
@@ -4550,15 +4456,15 @@ async function generateUnshieldProof(inputs, options = {}) {
|
|
|
4550
4456
|
change_blinding: changeBlinding.toString(),
|
|
4551
4457
|
change_owner_pubkey: changeOwnerPubkey.toString()
|
|
4552
4458
|
};
|
|
4553
|
-
const provider = options.provider ?? new
|
|
4459
|
+
const provider = options.provider ?? new import_proof_generator.WebArtifactProvider();
|
|
4554
4460
|
const opts = { provider };
|
|
4555
4461
|
if (options.verbose !== void 0) opts.verbose = options.verbose;
|
|
4556
|
-
const proofResult = await (0,
|
|
4462
|
+
const proofResult = await (0, import_proof_generator.generateProof)(import_proof_generator.CircuitType.Unshield, circuitInputs, opts);
|
|
4557
4463
|
return { ...proofResult, changeCommitment, changeValue, changeBlinding, changeOwnerPubkey };
|
|
4558
4464
|
}
|
|
4559
4465
|
|
|
4560
4466
|
// src/proof-generator/transfer.ts
|
|
4561
|
-
var
|
|
4467
|
+
var import_proof_generator2 = require("@orbinum/proof-generator");
|
|
4562
4468
|
async function generateTransferProof(params, options = {}) {
|
|
4563
4469
|
const root = leHexToBigint(params.merkleRoot).toString();
|
|
4564
4470
|
const [i0, i1] = params.inputs;
|
|
@@ -4583,47 +4489,38 @@ async function generateTransferProof(params, options = {}) {
|
|
|
4583
4489
|
output_owner_pubkeys: [o0.ownerPk.toString(), o1.ownerPk.toString()],
|
|
4584
4490
|
output_blindings: [o0.blinding.toString(), o1.blinding.toString()]
|
|
4585
4491
|
};
|
|
4586
|
-
const provider = options.provider ?? new
|
|
4492
|
+
const provider = options.provider ?? new import_proof_generator2.WebArtifactProvider();
|
|
4587
4493
|
const opts = { provider };
|
|
4588
4494
|
if (options.verbose !== void 0) opts.verbose = options.verbose;
|
|
4589
|
-
return (0,
|
|
4495
|
+
return (0, import_proof_generator2.generateProof)(import_proof_generator2.CircuitType.Transfer, circuitInputs, opts);
|
|
4590
4496
|
}
|
|
4591
4497
|
|
|
4592
4498
|
// src/proof-generator/fee-claim.ts
|
|
4593
|
-
var
|
|
4594
|
-
function hexSignalToBytes(hex) {
|
|
4595
|
-
const clean = hex.startsWith("0x") || hex.startsWith("0X") ? hex.slice(2) : hex;
|
|
4596
|
-
const padded = clean.padStart(64, "0");
|
|
4597
|
-
const bytes = new Uint8Array(32);
|
|
4598
|
-
for (let i = 0; i < 32; i++) {
|
|
4599
|
-
bytes[i] = parseInt(padded.slice(i * 2, i * 2 + 2), 16);
|
|
4600
|
-
}
|
|
4601
|
-
return bytes;
|
|
4602
|
-
}
|
|
4499
|
+
var import_proof_generator3 = require("@orbinum/proof-generator");
|
|
4603
4500
|
async function generateFeeClaimProof(inputs, options = {}) {
|
|
4604
|
-
|
|
4605
|
-
|
|
4606
|
-
|
|
4607
|
-
|
|
4608
|
-
inputs.
|
|
4609
|
-
inputs.
|
|
4610
|
-
|
|
4611
|
-
|
|
4612
|
-
|
|
4613
|
-
|
|
4614
|
-
|
|
4615
|
-
|
|
4616
|
-
|
|
4617
|
-
);
|
|
4618
|
-
const [, ,
|
|
4619
|
-
const
|
|
4620
|
-
|
|
4621
|
-
|
|
4622
|
-
|
|
4623
|
-
|
|
4501
|
+
if (inputs.amount <= 0n) {
|
|
4502
|
+
throw new Error("Fee claim amount must be greater than zero.");
|
|
4503
|
+
}
|
|
4504
|
+
const circuitInputs = {
|
|
4505
|
+
commitment: inputs.commitment.toString(),
|
|
4506
|
+
value: inputs.amount.toString(),
|
|
4507
|
+
asset_id: inputs.assetId.toString(),
|
|
4508
|
+
owner_pubkey: inputs.ownerPubkey.toString(),
|
|
4509
|
+
blinding: inputs.blinding.toString()
|
|
4510
|
+
};
|
|
4511
|
+
const provider = options.provider ?? new import_proof_generator3.WebArtifactProvider();
|
|
4512
|
+
const opts = { provider };
|
|
4513
|
+
if (options.verbose !== void 0) opts.verbose = options.verbose;
|
|
4514
|
+
const proofResult = await (0, import_proof_generator3.generateProof)(import_proof_generator3.CircuitType.ValueProof, circuitInputs, opts);
|
|
4515
|
+
const [sigCommitment, sigValue, sigAssetId, sigOwnerHash] = proofResult.publicSignals.map(BigInt);
|
|
4516
|
+
const buf = new Uint8Array(76);
|
|
4517
|
+
buf.set(bigintTo32Le(sigCommitment), 0);
|
|
4518
|
+
buf.set(bigintTo32Le(sigValue).subarray(0, 8), 32);
|
|
4519
|
+
buf.set(bigintTo32Le(sigAssetId).subarray(0, 4), 40);
|
|
4520
|
+
buf.set(bigintTo32Le(sigOwnerHash), 44);
|
|
4624
4521
|
return {
|
|
4625
|
-
proof:
|
|
4626
|
-
publicSignals: Array.from(
|
|
4522
|
+
proof: proofResult.proof,
|
|
4523
|
+
publicSignals: Array.from(buf)
|
|
4627
4524
|
};
|
|
4628
4525
|
}
|
|
4629
4526
|
|
|
@@ -4693,6 +4590,17 @@ function decodePrecompileCalldata(address, input) {
|
|
|
4693
4590
|
return { fnSig, args: {} };
|
|
4694
4591
|
}
|
|
4695
4592
|
}
|
|
4593
|
+
if (fnSig.startsWith("claimShieldedFees(")) {
|
|
4594
|
+
try {
|
|
4595
|
+
const data = fromHex(input.slice(10));
|
|
4596
|
+
const commitment = toHex(data.slice(0, 32));
|
|
4597
|
+
const amount = decodeUint(data, 32);
|
|
4598
|
+
const assetId = decodeUint(data, 64);
|
|
4599
|
+
return { fnSig, args: { commitment, amount, assetId } };
|
|
4600
|
+
} catch {
|
|
4601
|
+
return { fnSig, args: {} };
|
|
4602
|
+
}
|
|
4603
|
+
}
|
|
4696
4604
|
return { fnSig, args: {} };
|
|
4697
4605
|
}
|
|
4698
4606
|
|
|
@@ -4700,8 +4608,8 @@ function decodePrecompileCalldata(address, input) {
|
|
|
4700
4608
|
var CircuitId = {
|
|
4701
4609
|
Transfer: 1,
|
|
4702
4610
|
Unshield: 2,
|
|
4703
|
-
|
|
4704
|
-
PrivateLink:
|
|
4611
|
+
ValueProof: 4,
|
|
4612
|
+
PrivateLink: 5
|
|
4705
4613
|
};
|
|
4706
4614
|
|
|
4707
4615
|
// src/utils/string.ts
|
|
@@ -4890,39 +4798,6 @@ function mapExtrinsicArgs(section, method, args) {
|
|
|
4890
4798
|
recipient: get(5, "recipient")
|
|
4891
4799
|
};
|
|
4892
4800
|
}
|
|
4893
|
-
if (m_norm === "setauditpolicy") {
|
|
4894
|
-
return {
|
|
4895
|
-
auditors: get(0, "auditors"),
|
|
4896
|
-
conditions: get(1, "conditions"),
|
|
4897
|
-
max_frequency: get(2, "max_frequency"),
|
|
4898
|
-
valid_until: get(3, "valid_until")
|
|
4899
|
-
};
|
|
4900
|
-
}
|
|
4901
|
-
if (m_norm === "requestdisclosure") {
|
|
4902
|
-
return {
|
|
4903
|
-
target: get(0, "target"),
|
|
4904
|
-
commitment: get(1, "commitment"),
|
|
4905
|
-
required_fields: get(2, "required_fields"),
|
|
4906
|
-
reason: get(3, "reason"),
|
|
4907
|
-
auditor_bjj_pk_x: get(4, "auditor_bjj_pk_x"),
|
|
4908
|
-
auditor_bjj_pk_y: get(5, "auditor_bjj_pk_y")
|
|
4909
|
-
};
|
|
4910
|
-
}
|
|
4911
|
-
if (m_norm === "disclose") {
|
|
4912
|
-
return {
|
|
4913
|
-
commitment: get(0, "commitment"),
|
|
4914
|
-
proof_bytes: get(1, "proof_bytes"),
|
|
4915
|
-
public_signals: get(2, "public_signals"),
|
|
4916
|
-
auditor: get(3, "auditor")
|
|
4917
|
-
};
|
|
4918
|
-
}
|
|
4919
|
-
if (m_norm === "rejectdisclosure") {
|
|
4920
|
-
return {
|
|
4921
|
-
auditor: get(0, "auditor"),
|
|
4922
|
-
commitment: get(1, "commitment"),
|
|
4923
|
-
reason: get(2, "reason")
|
|
4924
|
-
};
|
|
4925
|
-
}
|
|
4926
4801
|
if (m_norm === "registerasset") {
|
|
4927
4802
|
return {
|
|
4928
4803
|
name: get(0, "name"),
|
|
@@ -4937,19 +4812,6 @@ function mapExtrinsicArgs(section, method, args) {
|
|
|
4937
4812
|
if (m_norm === "unverifyasset") {
|
|
4938
4813
|
return { asset_id: get(0, "asset_id") };
|
|
4939
4814
|
}
|
|
4940
|
-
if (m_norm === "batchsubmitdisclosureproofs") {
|
|
4941
|
-
return { submissions: get(0, "submissions") };
|
|
4942
|
-
}
|
|
4943
|
-
if (m_norm === "pruneexpiredrequest") {
|
|
4944
|
-
return {
|
|
4945
|
-
target: get(0, "target"),
|
|
4946
|
-
auditor: get(1, "auditor"),
|
|
4947
|
-
commitment: get(2, "commitment")
|
|
4948
|
-
};
|
|
4949
|
-
}
|
|
4950
|
-
if (m_norm === "revokedisclosurerecord") {
|
|
4951
|
-
return { commitment: get(0, "commitment") };
|
|
4952
|
-
}
|
|
4953
4815
|
}
|
|
4954
4816
|
if (s === "ethereum" && m === "transact") {
|
|
4955
4817
|
return { transaction: get(0, "transaction") };
|
|
@@ -5173,51 +5035,6 @@ function mapZkEventData(method, data) {
|
|
|
5173
5035
|
};
|
|
5174
5036
|
}
|
|
5175
5037
|
const m_norm = m.replace(/_/g, "");
|
|
5176
|
-
if (m_norm === "auditpolicyset") {
|
|
5177
|
-
return {
|
|
5178
|
-
account: get(0, "account"),
|
|
5179
|
-
version: get(1, "version")
|
|
5180
|
-
};
|
|
5181
|
-
}
|
|
5182
|
-
if (m_norm === "disclosed") {
|
|
5183
|
-
return {
|
|
5184
|
-
target: get(0, "target"),
|
|
5185
|
-
auditor: get(1, "auditor"),
|
|
5186
|
-
commitment: get(2, "commitment"),
|
|
5187
|
-
signals: get(3, "signals")
|
|
5188
|
-
};
|
|
5189
|
-
}
|
|
5190
|
-
if (m_norm === "disclosurerequested") {
|
|
5191
|
-
return {
|
|
5192
|
-
target: get(0, "target"),
|
|
5193
|
-
auditor: get(1, "auditor"),
|
|
5194
|
-
commitment: get(2, "commitment"),
|
|
5195
|
-
required_fields: get(3, "required_fields"),
|
|
5196
|
-
auditor_bjj_pk_x: get(4, "auditor_bjj_pk_x"),
|
|
5197
|
-
auditor_bjj_pk_y: get(5, "auditor_bjj_pk_y")
|
|
5198
|
-
};
|
|
5199
|
-
}
|
|
5200
|
-
if (m_norm === "disclosurerejected") {
|
|
5201
|
-
return {
|
|
5202
|
-
target: get(0, "target"),
|
|
5203
|
-
auditor: get(1, "auditor"),
|
|
5204
|
-
commitment: get(2, "commitment"),
|
|
5205
|
-
reason: get(3, "reason")
|
|
5206
|
-
};
|
|
5207
|
-
}
|
|
5208
|
-
if (m_norm === "disclosurerequestexpired") {
|
|
5209
|
-
return {
|
|
5210
|
-
target: get(0, "target"),
|
|
5211
|
-
auditor: get(1, "auditor"),
|
|
5212
|
-
commitment: get(2, "commitment")
|
|
5213
|
-
};
|
|
5214
|
-
}
|
|
5215
|
-
if (m_norm === "disclosurerecordrevoked") {
|
|
5216
|
-
return {
|
|
5217
|
-
who: get(0, "who"),
|
|
5218
|
-
commitment: get(1, "commitment")
|
|
5219
|
-
};
|
|
5220
|
-
}
|
|
5221
5038
|
if (m_norm === "assetregistered") {
|
|
5222
5039
|
return { asset_id: get(0, "asset_id") };
|
|
5223
5040
|
}
|
|
@@ -5497,17 +5314,16 @@ var import_polkadot_api4 = require("polkadot-api");
|
|
|
5497
5314
|
bigintTo32Be,
|
|
5498
5315
|
bigintTo32Le,
|
|
5499
5316
|
bigintTo32LeArr,
|
|
5500
|
-
buildDisclosurePublicSignals,
|
|
5501
5317
|
buildDummyTransferInput,
|
|
5502
5318
|
bytesToBigintLE,
|
|
5503
5319
|
computeNullifier,
|
|
5504
5320
|
computePathIndices,
|
|
5505
5321
|
connectInjectedExtension,
|
|
5322
|
+
createNoteDisclosureKey,
|
|
5323
|
+
decodeNoteDisclosureKey,
|
|
5506
5324
|
decodePrecompileCalldata,
|
|
5507
|
-
decryptDisclosureSignals,
|
|
5508
5325
|
decryptJson,
|
|
5509
5326
|
decryptNoteRecord,
|
|
5510
|
-
deriveBabyJubjubKeypair,
|
|
5511
5327
|
deriveMasterKeyBytes,
|
|
5512
5328
|
deriveOwnerPk,
|
|
5513
5329
|
deriveSpendingKeyFromSignature,
|
|
@@ -5528,7 +5344,6 @@ var import_polkadot_api4 = require("polkadot-api");
|
|
|
5528
5344
|
formatORB,
|
|
5529
5345
|
fromBase64,
|
|
5530
5346
|
fromHex,
|
|
5531
|
-
generateDisclosureProof,
|
|
5532
5347
|
generateFeeClaimProof,
|
|
5533
5348
|
generateTransferProof,
|
|
5534
5349
|
generateUnshieldProof,
|