@obelyzk/sdk 0.5.0 → 1.0.1

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.
@@ -23,36 +23,53 @@ __export(obelysk_exports, {
23
23
  CURVE_ORDER: () => CURVE_ORDER,
24
24
  ConfidentialTransferClient: () => ConfidentialTransferClient,
25
25
  DARKPOOL_ASSET_IDS: () => DARKPOOL_ASSET_IDS,
26
+ DENOMINATION_BY_SYMBOL: () => DENOMINATION_BY_SYMBOL,
26
27
  DarkPoolClient: () => DarkPoolClient,
28
+ ETH_DENOMINATIONS: () => ETH_DENOMINATIONS,
27
29
  FIELD_PRIME: () => FIELD_PRIME,
28
30
  GENERATOR_G: () => GENERATOR_G,
29
31
  GENERATOR_H: () => GENERATOR_H,
30
32
  MAINNET_PRIVACY_POOLS: () => MAINNET_PRIVACY_POOLS,
31
33
  MAINNET_TOKENS: () => MAINNET_TOKENS,
34
+ OTCOrderbookClient: () => OTCOrderbookClient,
32
35
  ObelyskClient: () => ObelyskClient,
33
36
  ObelyskPrivacy: () => ObelyskPrivacy,
37
+ OrderSide: () => OrderSide,
38
+ OrderStatus: () => OrderStatus,
39
+ OrderType: () => OrderType,
34
40
  PrivacyPoolClient: () => PrivacyPoolClient,
35
41
  PrivacyRouterClient: () => PrivacyRouterClient,
36
42
  ProverStakingClient: () => ProverStakingClient,
43
+ SAGE_DENOMINATIONS: () => SAGE_DENOMINATIONS,
44
+ STRK_DENOMINATIONS: () => STRK_DENOMINATIONS,
37
45
  ShieldedSwapClient: () => ShieldedSwapClient,
38
46
  StealthClient: () => StealthClient,
39
47
  TOKEN_DECIMALS: () => TOKEN_DECIMALS,
48
+ USDC_DENOMINATIONS: () => USDC_DENOMINATIONS,
49
+ VM31BridgeClient: () => VM31BridgeClient,
50
+ VM31VaultClient: () => VM31VaultClient,
40
51
  VM31_ASSET_IDS: () => VM31_ASSET_IDS,
52
+ VM31_DENOMINATIONS: () => VM31_DENOMINATIONS,
53
+ WBTC_DENOMINATIONS: () => WBTC_DENOMINATIONS,
41
54
  commitmentToHash: () => commitmentToHash,
42
55
  createAEHint: () => createAEHint,
43
56
  createEncryptionProof: () => createEncryptionProof,
44
57
  deriveNullifier: () => deriveNullifier,
45
58
  ecAdd: () => ecAdd2,
46
59
  ecMul: () => ecMul2,
60
+ eciesEncrypt: () => eciesEncrypt,
47
61
  elgamalEncrypt: () => elgamalEncrypt,
48
62
  formatAmount: () => formatAmount,
49
63
  getContracts: () => getContracts,
64
+ getDenominations: () => getDenominations,
50
65
  getRpcUrl: () => getRpcUrl,
51
66
  mod: () => mod,
52
67
  modInverse: () => modInverse,
53
68
  parseAmount: () => parseAmount,
54
69
  pedersenCommit: () => pedersenCommit,
55
- randomScalar: () => randomScalar2
70
+ randomScalar: () => randomScalar2,
71
+ splitIntoDenominations: () => splitIntoDenominations,
72
+ validateDenomination: () => validateDenomination
56
73
  });
57
74
  module.exports = __toCommonJS(obelysk_exports);
58
75
 
@@ -996,6 +1013,124 @@ var DarkPoolClient = class {
996
1013
  await this.obelysk.provider.waitForTransaction(result.transaction_hash);
997
1014
  return { txHash: result.transaction_hash };
998
1015
  }
1016
+ /** Cancel an order before reveal. */
1017
+ async cancelOrder(orderId) {
1018
+ const account = this.obelysk.requireAccount();
1019
+ const low = (orderId & (1n << 128n) - 1n).toString();
1020
+ const high = (orderId >> 128n).toString();
1021
+ const result = await account.execute([{
1022
+ contractAddress: this.darkPoolAddress,
1023
+ entrypoint: "cancel_order",
1024
+ calldata: [low, high]
1025
+ }]);
1026
+ return result.transaction_hash;
1027
+ }
1028
+ /** Claim fills after epoch settlement. */
1029
+ async claimFill(params) {
1030
+ const account = this.obelysk.requireAccount();
1031
+ const oLow = (params.orderId & (1n << 128n) - 1n).toString();
1032
+ const oHigh = (params.orderId >> 128n).toString();
1033
+ const result = await account.execute([{
1034
+ contractAddress: this.darkPoolAddress,
1035
+ entrypoint: "claim_fill",
1036
+ calldata: [
1037
+ oLow,
1038
+ oHigh,
1039
+ params.receiveCipher.c1.x.toString(),
1040
+ params.receiveCipher.c1.y.toString(),
1041
+ params.receiveCipher.c2.x.toString(),
1042
+ params.receiveCipher.c2.y.toString(),
1043
+ params.receiveHint.toString(),
1044
+ params.receiveProof.commitment.toString(),
1045
+ params.receiveProof.challenge.toString(),
1046
+ params.receiveProof.response.toString(),
1047
+ params.spendCipher.c1.x.toString(),
1048
+ params.spendCipher.c1.y.toString(),
1049
+ params.spendCipher.c2.x.toString(),
1050
+ params.spendCipher.c2.y.toString(),
1051
+ params.spendHint.toString(),
1052
+ params.spendProof.commitment.toString(),
1053
+ params.spendProof.challenge.toString(),
1054
+ params.spendProof.response.toString()
1055
+ ]
1056
+ }]);
1057
+ return result.transaction_hash;
1058
+ }
1059
+ /** Register your ElGamal public key with the DarkPool. */
1060
+ async registerPubkey(pubkey) {
1061
+ const account = this.obelysk.requireAccount();
1062
+ const result = await account.execute([{
1063
+ contractAddress: this.darkPoolAddress,
1064
+ entrypoint: "register_pubkey",
1065
+ calldata: [pubkey.x.toString(), pubkey.y.toString()]
1066
+ }]);
1067
+ return result.transaction_hash;
1068
+ }
1069
+ /** Get the result of a settled epoch. */
1070
+ async getEpochResult(epochId) {
1071
+ try {
1072
+ const result = await this.obelysk.provider.callContract({
1073
+ contractAddress: this.darkPoolAddress,
1074
+ entrypoint: "get_epoch_result",
1075
+ calldata: [epochId.toString()]
1076
+ });
1077
+ if (result.length < 2) return null;
1078
+ const settled = BigInt(result[0]) !== 0n;
1079
+ const priceCount = Number(BigInt(result[1]));
1080
+ const clearingPrices = result.slice(2, 2 + priceCount);
1081
+ return { settled, clearingPrices };
1082
+ } catch {
1083
+ return null;
1084
+ }
1085
+ }
1086
+ /** Check if an order has been claimed. */
1087
+ async isOrderClaimed(orderId) {
1088
+ try {
1089
+ const low = (orderId & (1n << 128n) - 1n).toString();
1090
+ const high = (orderId >> 128n).toString();
1091
+ const result = await this.obelysk.provider.callContract({
1092
+ contractAddress: this.darkPoolAddress,
1093
+ entrypoint: "is_order_claimed",
1094
+ calldata: [low, high]
1095
+ });
1096
+ return BigInt(result[0]) !== 0n;
1097
+ } catch {
1098
+ return false;
1099
+ }
1100
+ }
1101
+ /** Get a trader's registered public key. */
1102
+ async getTraderPubkey(address) {
1103
+ try {
1104
+ const result = await this.obelysk.provider.callContract({
1105
+ contractAddress: this.darkPoolAddress,
1106
+ entrypoint: "get_trader_pubkey",
1107
+ calldata: [address]
1108
+ });
1109
+ const x = BigInt(result[0]);
1110
+ const y = BigInt(result[1]);
1111
+ if (x === 0n && y === 0n) return null;
1112
+ return { x, y };
1113
+ } catch {
1114
+ return null;
1115
+ }
1116
+ }
1117
+ /** Get encrypted balance for a trader and asset. */
1118
+ async getEncryptedBalance(address, assetId) {
1119
+ try {
1120
+ const result = await this.obelysk.provider.callContract({
1121
+ contractAddress: this.darkPoolAddress,
1122
+ entrypoint: "get_encrypted_balance",
1123
+ calldata: [address, assetId]
1124
+ });
1125
+ if (result.length < 4) return null;
1126
+ return {
1127
+ c1: { x: BigInt(result[0]), y: BigInt(result[1]) },
1128
+ c2: { x: BigInt(result[2]), y: BigInt(result[3]) }
1129
+ };
1130
+ } catch {
1131
+ return null;
1132
+ }
1133
+ }
999
1134
  };
1000
1135
 
1001
1136
  // src/obelysk/stealth.ts
@@ -1155,6 +1290,102 @@ var StealthClient = class {
1155
1290
  await this.obelysk.provider.waitForTransaction(result.transaction_hash);
1156
1291
  return { txHash: result.transaction_hash };
1157
1292
  }
1293
+ /** Claim a stealth payment. */
1294
+ async claim(params) {
1295
+ const account = this.obelysk.requireAccount();
1296
+ const p = params.spendingProof;
1297
+ const result = await account.execute([{
1298
+ contractAddress: this.registryAddress,
1299
+ entrypoint: "claim_stealth_payment",
1300
+ calldata: [
1301
+ params.announcementIndex.toString(),
1302
+ p.commitment.toString(),
1303
+ p.challenge.toString(),
1304
+ p.response.toString(),
1305
+ p.stealthPubkey.x.toString(),
1306
+ p.stealthPubkey.y.toString(),
1307
+ params.recipient
1308
+ ]
1309
+ }]);
1310
+ return result.transaction_hash;
1311
+ }
1312
+ /** Batch claim multiple stealth payments. */
1313
+ async batchClaim(params) {
1314
+ const account = this.obelysk.requireAccount();
1315
+ const calldata = [
1316
+ params.announcementIndices.length.toString(),
1317
+ ...params.announcementIndices.map((i) => i.toString()),
1318
+ params.spendingProofs.length.toString(),
1319
+ ...params.spendingProofs.flatMap((p) => [
1320
+ p.commitment.toString(),
1321
+ p.challenge.toString(),
1322
+ p.response.toString(),
1323
+ p.stealthPubkey.x.toString(),
1324
+ p.stealthPubkey.y.toString()
1325
+ ]),
1326
+ params.recipient
1327
+ ];
1328
+ const result = await account.execute([{
1329
+ contractAddress: this.registryAddress,
1330
+ entrypoint: "batch_claim_stealth_payments",
1331
+ calldata
1332
+ }]);
1333
+ return result.transaction_hash;
1334
+ }
1335
+ /** Update your stealth meta-address. */
1336
+ async updateMetaAddress(spendPubKey, viewPubKey) {
1337
+ const account = this.obelysk.requireAccount();
1338
+ const result = await account.execute([{
1339
+ contractAddress: this.registryAddress,
1340
+ entrypoint: "update_meta_address",
1341
+ calldata: [spendPubKey.x.toString(), spendPubKey.y.toString(), viewPubKey.x.toString(), viewPubKey.y.toString()]
1342
+ }]);
1343
+ return result.transaction_hash;
1344
+ }
1345
+ /** Get a specific announcement by index. */
1346
+ async getAnnouncement(index) {
1347
+ try {
1348
+ const result = await this.obelysk.provider.callContract({
1349
+ contractAddress: this.registryAddress,
1350
+ entrypoint: "get_announcement",
1351
+ calldata: [index.toString()]
1352
+ });
1353
+ return {
1354
+ ephemeralPubkey: { x: BigInt(result[0]), y: BigInt(result[1]) },
1355
+ stealthAddress: result[2],
1356
+ viewTag: result[3],
1357
+ token: result[4],
1358
+ amount: BigInt(result[5])
1359
+ };
1360
+ } catch {
1361
+ return null;
1362
+ }
1363
+ }
1364
+ /** Get announcements in a range. */
1365
+ async getAnnouncementsRange(start, end) {
1366
+ try {
1367
+ const result = await this.obelysk.provider.callContract({
1368
+ contractAddress: this.registryAddress,
1369
+ entrypoint: "get_announcements_range",
1370
+ calldata: [start.toString(), end.toString()]
1371
+ });
1372
+ const count = Number(BigInt(result[0]));
1373
+ const items = [];
1374
+ for (let i = 0; i < count; i++) {
1375
+ const base = 1 + i * 6;
1376
+ items.push({
1377
+ ephemeralPubkey: { x: BigInt(result[base]), y: BigInt(result[base + 1]) },
1378
+ stealthAddress: result[base + 2],
1379
+ viewTag: result[base + 3],
1380
+ token: result[base + 4],
1381
+ amount: BigInt(result[base + 5])
1382
+ });
1383
+ }
1384
+ return items;
1385
+ } catch {
1386
+ return [];
1387
+ }
1388
+ }
1158
1389
  };
1159
1390
 
1160
1391
  // src/obelysk/confidentialTransfer.ts
@@ -1247,6 +1478,78 @@ var ConfidentialTransferClient = class {
1247
1478
  return null;
1248
1479
  }
1249
1480
  }
1481
+ /** Register an ElGamal public key for confidential transfers. */
1482
+ async register(publicKey) {
1483
+ const account = this.obelysk.requireAccount();
1484
+ const result = await account.execute([{
1485
+ contractAddress: this.contractAddress,
1486
+ entrypoint: "register",
1487
+ calldata: [publicKey.x.toString(), publicKey.y.toString()]
1488
+ }]);
1489
+ return result.transaction_hash;
1490
+ }
1491
+ /** Fund: deposit public tokens into encrypted balance. */
1492
+ async fund(params) {
1493
+ const account = this.obelysk.requireAccount();
1494
+ const low = (params.amount & (1n << 128n) - 1n).toString();
1495
+ const high = (params.amount >> 128n).toString();
1496
+ const result = await account.execute([{
1497
+ contractAddress: this.contractAddress,
1498
+ entrypoint: "fund",
1499
+ calldata: [params.assetId.toString(), low, high, params.encryptionRandomness.toString(), params.aeHint.toString()]
1500
+ }]);
1501
+ return result.transaction_hash;
1502
+ }
1503
+ /** Fund another account's encrypted balance. */
1504
+ async fundFor(params) {
1505
+ const signer = this.obelysk.requireAccount();
1506
+ const low = (params.amount & (1n << 128n) - 1n).toString();
1507
+ const high = (params.amount >> 128n).toString();
1508
+ const result = await signer.execute([{
1509
+ contractAddress: this.contractAddress,
1510
+ entrypoint: "fund_for",
1511
+ calldata: [params.account, params.assetId.toString(), low, high, params.encryptionRandomness.toString(), params.aeHint.toString()]
1512
+ }]);
1513
+ return result.transaction_hash;
1514
+ }
1515
+ /** Rollover: claim pending incoming transfers into your balance. */
1516
+ async rollover(assetId) {
1517
+ const account = this.obelysk.requireAccount();
1518
+ const result = await account.execute([{
1519
+ contractAddress: this.contractAddress,
1520
+ entrypoint: "rollover",
1521
+ calldata: [assetId.toString()]
1522
+ }]);
1523
+ return result.transaction_hash;
1524
+ }
1525
+ /** Withdraw: convert encrypted balance back to public tokens. */
1526
+ async withdraw(params) {
1527
+ const account = this.obelysk.requireAccount();
1528
+ const low = (params.amount & (1n << 128n) - 1n).toString();
1529
+ const high = (params.amount >> 128n).toString();
1530
+ const result = await account.execute([{
1531
+ contractAddress: this.contractAddress,
1532
+ entrypoint: "withdraw",
1533
+ calldata: [params.to, params.assetId.toString(), low, high, params.proof.commitment.toString(), params.proof.challenge.toString(), params.proof.response.toString()]
1534
+ }]);
1535
+ return result.transaction_hash;
1536
+ }
1537
+ /** Get a registered public key. */
1538
+ async getPublicKey(address) {
1539
+ try {
1540
+ const result = await this.obelysk.provider.callContract({
1541
+ contractAddress: this.contractAddress,
1542
+ entrypoint: "get_public_key",
1543
+ calldata: [address]
1544
+ });
1545
+ const x = BigInt(result[0]);
1546
+ const y = BigInt(result[1]);
1547
+ if (x === 0n && y === 0n) return null;
1548
+ return { x, y };
1549
+ } catch {
1550
+ return null;
1551
+ }
1552
+ }
1250
1553
  };
1251
1554
 
1252
1555
  // src/obelysk/proverStaking.ts
@@ -1591,6 +1894,133 @@ var PrivacyRouterClient = class {
1591
1894
  });
1592
1895
  return Number(BigInt(result[0]));
1593
1896
  }
1897
+ /** Register an account with the privacy router. */
1898
+ async registerAccount(publicKey) {
1899
+ const account = this.obelysk.requireAccount();
1900
+ const result = await account.execute([{
1901
+ contractAddress: this.contractAddress,
1902
+ entrypoint: "register_account",
1903
+ calldata: [publicKey.x.toString(), publicKey.y.toString()]
1904
+ }]);
1905
+ return result.transaction_hash;
1906
+ }
1907
+ /** Deposit tokens into encrypted balance. */
1908
+ async deposit(params) {
1909
+ const account = this.obelysk.requireAccount();
1910
+ const low = (params.amount & (1n << 128n) - 1n).toString();
1911
+ const high = (params.amount >> 128n).toString();
1912
+ const result = await account.execute([{
1913
+ contractAddress: this.contractAddress,
1914
+ entrypoint: "deposit",
1915
+ calldata: [
1916
+ low,
1917
+ high,
1918
+ params.encryptedAmount.c1.x.toString(),
1919
+ params.encryptedAmount.c1.y.toString(),
1920
+ params.encryptedAmount.c2.x.toString(),
1921
+ params.encryptedAmount.c2.y.toString(),
1922
+ params.proof.commitment.toString(),
1923
+ params.proof.challenge.toString(),
1924
+ params.proof.response.toString()
1925
+ ]
1926
+ }]);
1927
+ return result.transaction_hash;
1928
+ }
1929
+ /** Withdraw from encrypted balance to public. */
1930
+ async withdraw(params) {
1931
+ const account = this.obelysk.requireAccount();
1932
+ const low = (params.amount & (1n << 128n) - 1n).toString();
1933
+ const high = (params.amount >> 128n).toString();
1934
+ const calldata = [
1935
+ low,
1936
+ high,
1937
+ params.encryptedDelta.c1.x.toString(),
1938
+ params.encryptedDelta.c1.y.toString(),
1939
+ params.encryptedDelta.c2.x.toString(),
1940
+ params.encryptedDelta.c2.y.toString(),
1941
+ params.proof.commitment.toString(),
1942
+ params.proof.challenge.toString(),
1943
+ params.proof.response.toString()
1944
+ ];
1945
+ if (params.rangeProofData) calldata.push(...params.rangeProofData);
1946
+ const result = await account.execute([{
1947
+ contractAddress: this.contractAddress,
1948
+ entrypoint: "withdraw",
1949
+ calldata
1950
+ }]);
1951
+ return result.transaction_hash;
1952
+ }
1953
+ /** Private transfer between accounts. */
1954
+ async privateTransfer(params) {
1955
+ const account = this.obelysk.requireAccount();
1956
+ const result = await account.execute([{
1957
+ contractAddress: this.contractAddress,
1958
+ entrypoint: "private_transfer",
1959
+ calldata: [
1960
+ params.to,
1961
+ params.senderCipher.c1.x.toString(),
1962
+ params.senderCipher.c1.y.toString(),
1963
+ params.senderCipher.c2.x.toString(),
1964
+ params.senderCipher.c2.y.toString(),
1965
+ params.receiverCipher.c1.x.toString(),
1966
+ params.receiverCipher.c1.y.toString(),
1967
+ params.receiverCipher.c2.x.toString(),
1968
+ params.receiverCipher.c2.y.toString(),
1969
+ params.proof.commitment.toString(),
1970
+ params.proof.challenge.toString(),
1971
+ params.proof.response.toString(),
1972
+ params.senderAeHint.toString(),
1973
+ params.receiverAeHint.toString()
1974
+ ]
1975
+ }]);
1976
+ return result.transaction_hash;
1977
+ }
1978
+ /** Request disclosure of a nullifier (audit). */
1979
+ async requestDisclosure(nullifier, reason) {
1980
+ const account = this.obelysk.requireAccount();
1981
+ const result = await account.execute([{
1982
+ contractAddress: this.contractAddress,
1983
+ entrypoint: "request_disclosure",
1984
+ calldata: [nullifier, reason]
1985
+ }]);
1986
+ return result.transaction_hash;
1987
+ }
1988
+ /** Ragequit: emergency withdrawal with proof. */
1989
+ async ragequit(proof) {
1990
+ const account = this.obelysk.requireAccount();
1991
+ const result = await account.execute([{
1992
+ contractAddress: this.contractAddress,
1993
+ entrypoint: "ragequit",
1994
+ calldata: proof
1995
+ }]);
1996
+ return result.transaction_hash;
1997
+ }
1998
+ /** Get the nullifier tree state. */
1999
+ async getNullifierTreeState() {
2000
+ const result = await this.obelysk.provider.callContract({
2001
+ contractAddress: this.contractAddress,
2002
+ entrypoint: "get_nullifier_tree_state",
2003
+ calldata: []
2004
+ });
2005
+ return { root: result[0], size: Number(BigInt(result[1])) };
2006
+ }
2007
+ /** Get account balance hints (for O(1) decryption). */
2008
+ async getAccountHints(address) {
2009
+ try {
2010
+ const result = await this.obelysk.provider.callContract({
2011
+ contractAddress: this.contractAddress,
2012
+ entrypoint: "get_account_hints",
2013
+ calldata: [address]
2014
+ });
2015
+ return {
2016
+ balanceHint: BigInt(result[0]),
2017
+ pendingInHint: BigInt(result[1]),
2018
+ pendingOutHint: BigInt(result[2])
2019
+ };
2020
+ } catch {
2021
+ return null;
2022
+ }
2023
+ }
1594
2024
  };
1595
2025
 
1596
2026
  // src/obelysk/shieldedSwap.ts
@@ -1659,6 +2089,1157 @@ var ShieldedSwapClient = class {
1659
2089
  });
1660
2090
  return result[0];
1661
2091
  }
2092
+ /**
2093
+ * Execute a shielded swap (privacy pool -> AMM -> re-deposit).
2094
+ * This is the full privacy-preserving swap flow.
2095
+ */
2096
+ async shieldedSwap(params) {
2097
+ const account = this.obelysk.requireAccount();
2098
+ const result = await account.execute([{
2099
+ contractAddress: this.contractAddress,
2100
+ entrypoint: "shielded_swap",
2101
+ calldata: [
2102
+ params.tokenIn,
2103
+ params.tokenOut,
2104
+ params.amountIn.toString(),
2105
+ params.minAmountOut.toString(),
2106
+ params.nullifier,
2107
+ params.merkleRoot,
2108
+ ...params.merkleProof,
2109
+ params.newCommitment,
2110
+ params.encryptedAmount.toString(),
2111
+ params.proof
2112
+ ]
2113
+ }]);
2114
+ return result.transaction_hash;
2115
+ }
2116
+ };
2117
+
2118
+ // src/obelysk/ecies.ts
2119
+ var HKDF_INFO = "obelysk-ecies-v1";
2120
+ var ECIES_VERSION = 1;
2121
+ async function eciesEncrypt(payload, relayerPubkeyHex) {
2122
+ const subtle = getCrypto();
2123
+ const relayerPubkeyBytes = hexToBytes(relayerPubkeyHex);
2124
+ if (relayerPubkeyBytes.length !== 32) {
2125
+ throw new Error(`Invalid relayer public key length: ${relayerPubkeyBytes.length} (expected 32)`);
2126
+ }
2127
+ const relayerPubkey = await subtle.importKey(
2128
+ "raw",
2129
+ relayerPubkeyBytes.buffer,
2130
+ { name: "X25519" },
2131
+ false,
2132
+ []
2133
+ );
2134
+ const ephemeralKeyPair = await subtle.generateKey(
2135
+ { name: "X25519" },
2136
+ true,
2137
+ ["deriveBits"]
2138
+ );
2139
+ const sharedBits = await subtle.deriveBits(
2140
+ { name: "X25519", public: relayerPubkey },
2141
+ ephemeralKeyPair.privateKey,
2142
+ 256
2143
+ );
2144
+ const sharedKey = await subtle.importKey(
2145
+ "raw",
2146
+ sharedBits,
2147
+ { name: "HKDF" },
2148
+ false,
2149
+ ["deriveKey"]
2150
+ );
2151
+ const aesKey = await subtle.deriveKey(
2152
+ {
2153
+ name: "HKDF",
2154
+ hash: "SHA-256",
2155
+ salt: new ArrayBuffer(0),
2156
+ info: new TextEncoder().encode(HKDF_INFO)
2157
+ },
2158
+ sharedKey,
2159
+ { name: "AES-GCM", length: 256 },
2160
+ false,
2161
+ ["encrypt"]
2162
+ );
2163
+ const nonce = getRandomBytes(12);
2164
+ const plaintext = new TextEncoder().encode(JSON.stringify(payload));
2165
+ const ciphertext = await subtle.encrypt(
2166
+ { name: "AES-GCM", iv: nonce },
2167
+ aesKey,
2168
+ plaintext
2169
+ );
2170
+ const ephPubRaw = await subtle.exportKey("raw", ephemeralKeyPair.publicKey);
2171
+ return {
2172
+ ephemeral_pubkey: bytesToHex(new Uint8Array(ephPubRaw)),
2173
+ ciphertext: bytesToBase64(new Uint8Array(ciphertext)),
2174
+ nonce: bytesToHex(nonce),
2175
+ version: ECIES_VERSION
2176
+ };
2177
+ }
2178
+ function getCrypto() {
2179
+ if (typeof globalThis.crypto?.subtle !== "undefined") {
2180
+ return globalThis.crypto.subtle;
2181
+ }
2182
+ try {
2183
+ const { webcrypto } = require("crypto");
2184
+ return webcrypto.subtle;
2185
+ } catch {
2186
+ throw new Error("ECIES requires Web Crypto API (Node 20+ or a modern browser)");
2187
+ }
2188
+ }
2189
+ function getRandomBytes(n) {
2190
+ if (typeof globalThis.crypto?.getRandomValues !== "undefined") {
2191
+ return globalThis.crypto.getRandomValues(new Uint8Array(n));
2192
+ }
2193
+ const { randomBytes: randomBytes2 } = require("crypto");
2194
+ return new Uint8Array(randomBytes2(n));
2195
+ }
2196
+ function hexToBytes(hex) {
2197
+ const clean = hex.startsWith("0x") ? hex.slice(2) : hex;
2198
+ const bytes = new Uint8Array(clean.length / 2);
2199
+ for (let i = 0; i < bytes.length; i++) {
2200
+ bytes[i] = parseInt(clean.slice(i * 2, i * 2 + 2), 16);
2201
+ }
2202
+ return bytes;
2203
+ }
2204
+ function bytesToHex(bytes) {
2205
+ return Array.from(bytes).map((b) => b.toString(16).padStart(2, "0")).join("");
2206
+ }
2207
+ function bytesToBase64(bytes) {
2208
+ if (typeof btoa === "function") {
2209
+ return btoa(String.fromCharCode(...bytes));
2210
+ }
2211
+ return Buffer.from(bytes).toString("base64");
2212
+ }
2213
+
2214
+ // src/obelysk/denominations.ts
2215
+ var WBTC_DENOMINATIONS = [
2216
+ 50000n,
2217
+ // 0.0005 BTC
2218
+ 100000n,
2219
+ // 0.001 BTC
2220
+ 500000n,
2221
+ // 0.005 BTC
2222
+ 1000000n,
2223
+ // 0.01 BTC
2224
+ 5000000n,
2225
+ // 0.05 BTC
2226
+ 10000000n
2227
+ // 0.1 BTC
2228
+ ];
2229
+ var SAGE_DENOMINATIONS = [
2230
+ 10000000000000000n,
2231
+ // 0.01 SAGE
2232
+ 50000000000000000n,
2233
+ // 0.05 SAGE
2234
+ 100000000000000000n,
2235
+ // 0.1 SAGE
2236
+ 500000000000000000n,
2237
+ // 0.5 SAGE
2238
+ 1000000000000000000n,
2239
+ // 1 SAGE
2240
+ 5000000000000000000n
2241
+ // 5 SAGE
2242
+ ];
2243
+ var ETH_DENOMINATIONS = [
2244
+ 1000000000000000n,
2245
+ // 0.001 ETH
2246
+ 5000000000000000n,
2247
+ // 0.005 ETH
2248
+ 10000000000000000n,
2249
+ // 0.01 ETH
2250
+ 50000000000000000n,
2251
+ // 0.05 ETH
2252
+ 100000000000000000n,
2253
+ // 0.1 ETH
2254
+ 500000000000000000n
2255
+ // 0.5 ETH
2256
+ ];
2257
+ var STRK_DENOMINATIONS = [
2258
+ 50000000000000000n,
2259
+ // 0.05 STRK
2260
+ 100000000000000000n,
2261
+ // 0.1 STRK
2262
+ 500000000000000000n,
2263
+ // 0.5 STRK
2264
+ 1000000000000000000n,
2265
+ // 1 STRK
2266
+ 5000000000000000000n
2267
+ // 5 STRK
2268
+ ];
2269
+ var USDC_DENOMINATIONS = [
2270
+ 1000000n,
2271
+ // 1 USDC
2272
+ 5000000n,
2273
+ // 5 USDC
2274
+ 10000000n,
2275
+ // 10 USDC
2276
+ 50000000n,
2277
+ // 50 USDC
2278
+ 100000000n,
2279
+ // 100 USDC
2280
+ 500000000n
2281
+ // 500 USDC
2282
+ ];
2283
+ var VM31_DENOMINATIONS = {
2284
+ 0: WBTC_DENOMINATIONS,
2285
+ 1: SAGE_DENOMINATIONS,
2286
+ 2: ETH_DENOMINATIONS,
2287
+ 3: STRK_DENOMINATIONS,
2288
+ 4: USDC_DENOMINATIONS
2289
+ };
2290
+ var DENOMINATION_BY_SYMBOL = {
2291
+ wbtc: WBTC_DENOMINATIONS,
2292
+ sage: SAGE_DENOMINATIONS,
2293
+ eth: ETH_DENOMINATIONS,
2294
+ strk: STRK_DENOMINATIONS,
2295
+ usdc: USDC_DENOMINATIONS
2296
+ };
2297
+ function validateDenomination(amount, assetIdOrSymbol) {
2298
+ let denoms;
2299
+ if (typeof assetIdOrSymbol === "number") {
2300
+ denoms = VM31_DENOMINATIONS[assetIdOrSymbol];
2301
+ } else {
2302
+ denoms = DENOMINATION_BY_SYMBOL[assetIdOrSymbol.toLowerCase()];
2303
+ }
2304
+ if (!denoms) return;
2305
+ if (!denoms.includes(amount)) {
2306
+ throw new Error(
2307
+ `Deposit must use a standard denomination for asset ${assetIdOrSymbol}. Got ${amount}. Valid: [${denoms.join(", ")}]`
2308
+ );
2309
+ }
2310
+ }
2311
+ function splitIntoDenominations(amount, assetIdOrSymbol) {
2312
+ let denoms;
2313
+ if (typeof assetIdOrSymbol === "number") {
2314
+ denoms = VM31_DENOMINATIONS[assetIdOrSymbol];
2315
+ } else {
2316
+ denoms = DENOMINATION_BY_SYMBOL[assetIdOrSymbol.toLowerCase()];
2317
+ }
2318
+ if (!denoms) return { denominations: [amount], remainder: 0n };
2319
+ const sorted = [...denoms].sort((a, b) => b > a ? 1 : b < a ? -1 : 0);
2320
+ const result = [];
2321
+ let remaining = amount;
2322
+ for (const denom of sorted) {
2323
+ while (remaining >= denom) {
2324
+ result.push(denom);
2325
+ remaining -= denom;
2326
+ }
2327
+ }
2328
+ return { denominations: result, remainder: remaining };
2329
+ }
2330
+ function getDenominations(assetIdOrSymbol) {
2331
+ if (typeof assetIdOrSymbol === "number") {
2332
+ return VM31_DENOMINATIONS[assetIdOrSymbol];
2333
+ }
2334
+ return DENOMINATION_BY_SYMBOL[assetIdOrSymbol.toLowerCase()];
2335
+ }
2336
+
2337
+ // src/obelysk/vm31Vault.ts
2338
+ var VM31VaultClient = class {
2339
+ constructor(obelysk) {
2340
+ this.obelysk = obelysk;
2341
+ }
2342
+ get contractAddress() {
2343
+ return this.obelysk.contracts.vm31_pool;
2344
+ }
2345
+ get relayerUrl() {
2346
+ return this.obelysk.relayerUrl ?? "https://relay.bitsage.network:3080";
2347
+ }
2348
+ get relayerApiKey() {
2349
+ return this.obelysk.relayerApiKey;
2350
+ }
2351
+ /** Cached relayer X25519 public key (fetched on first encrypted submit) */
2352
+ _relayerPubkey = null;
2353
+ async relayerFetch(path, init) {
2354
+ const url = `${this.relayerUrl}${path}`;
2355
+ const headers = { "Content-Type": "application/json" };
2356
+ if (this.relayerApiKey) headers["x-api-key"] = this.relayerApiKey;
2357
+ const res = await fetch(url, { ...init, headers: { ...headers, ...init?.headers } });
2358
+ if (!res.ok) {
2359
+ const body = await res.text().catch(() => "");
2360
+ throw new Error(`VM31 relayer ${res.status}: ${body}`);
2361
+ }
2362
+ return res.json();
2363
+ }
2364
+ /**
2365
+ * Submit a payload to the relayer, encrypted with ECIES.
2366
+ * Falls back to plaintext if `encrypt: false` is passed.
2367
+ */
2368
+ async relayerSubmit(payload, encrypt = true) {
2369
+ if (!encrypt) {
2370
+ return this.relayerFetch("/submit", {
2371
+ method: "POST",
2372
+ body: JSON.stringify(payload)
2373
+ });
2374
+ }
2375
+ if (!this._relayerPubkey) {
2376
+ const keyInfo = await this.getRelayerPublicKey();
2377
+ this._relayerPubkey = keyInfo.publicKey;
2378
+ }
2379
+ const envelope = await eciesEncrypt(payload, this._relayerPubkey);
2380
+ return this.relayerFetch("/submit", {
2381
+ method: "POST",
2382
+ body: JSON.stringify(envelope)
2383
+ });
2384
+ }
2385
+ // --------------------------------------------------------------------------
2386
+ // On-chain reads (callContract to vm31_pool)
2387
+ // --------------------------------------------------------------------------
2388
+ /** Get the current Merkle root of the VM31 commitment tree */
2389
+ async getMerkleRoot() {
2390
+ const result = await this.obelysk.provider.callContract({
2391
+ contractAddress: this.contractAddress,
2392
+ entrypoint: "get_merkle_root",
2393
+ calldata: []
2394
+ });
2395
+ return { lo: result[0], hi: result[1] };
2396
+ }
2397
+ /** Get the number of leaves in the commitment tree */
2398
+ async getTreeSize() {
2399
+ const result = await this.obelysk.provider.callContract({
2400
+ contractAddress: this.contractAddress,
2401
+ entrypoint: "get_tree_size",
2402
+ calldata: []
2403
+ });
2404
+ return Number(BigInt(result[0]));
2405
+ }
2406
+ /** Check if a nullifier has been spent */
2407
+ async isNullifierSpent(nullifier) {
2408
+ const result = await this.obelysk.provider.callContract({
2409
+ contractAddress: this.contractAddress,
2410
+ entrypoint: "is_nullifier_spent",
2411
+ calldata: [nullifier.lo, nullifier.hi]
2412
+ });
2413
+ return BigInt(result[0]) !== 0n;
2414
+ }
2415
+ /** Check if a Merkle root is known (valid historical root) */
2416
+ async isKnownRoot(root) {
2417
+ const result = await this.obelysk.provider.callContract({
2418
+ contractAddress: this.contractAddress,
2419
+ entrypoint: "is_known_root",
2420
+ calldata: [root.lo, root.hi]
2421
+ });
2422
+ return BigInt(result[0]) !== 0n;
2423
+ }
2424
+ /** Get the total balance of an asset held in the pool */
2425
+ async getAssetBalance(assetId) {
2426
+ const result = await this.obelysk.provider.callContract({
2427
+ contractAddress: this.contractAddress,
2428
+ entrypoint: "get_asset_balance",
2429
+ calldata: [assetId.toString()]
2430
+ });
2431
+ return BigInt(result[0]);
2432
+ }
2433
+ /** Get on-chain batch status (0=NONE, 1=SUBMITTED, 2=FINALIZED, 3=CANCELLED) */
2434
+ async getBatchStatus(batchId) {
2435
+ const result = await this.obelysk.provider.callContract({
2436
+ contractAddress: this.contractAddress,
2437
+ entrypoint: "get_batch_status",
2438
+ calldata: [batchId]
2439
+ });
2440
+ return Number(BigInt(result[0]));
2441
+ }
2442
+ /** Get the currently active batch ID */
2443
+ async getActiveBatchId() {
2444
+ const result = await this.obelysk.provider.callContract({
2445
+ contractAddress: this.contractAddress,
2446
+ entrypoint: "get_active_batch_id",
2447
+ calldata: []
2448
+ });
2449
+ return result[0];
2450
+ }
2451
+ /** Get total transaction count in a batch */
2452
+ async getBatchTotalTxs(batchId) {
2453
+ const result = await this.obelysk.provider.callContract({
2454
+ contractAddress: this.contractAddress,
2455
+ entrypoint: "get_batch_total_txs",
2456
+ calldata: [batchId]
2457
+ });
2458
+ return Number(BigInt(result[0]));
2459
+ }
2460
+ /** Get number of processed transactions in a batch */
2461
+ async getBatchProcessedCount(batchId) {
2462
+ const result = await this.obelysk.provider.callContract({
2463
+ contractAddress: this.contractAddress,
2464
+ entrypoint: "get_batch_processed_count",
2465
+ calldata: [batchId]
2466
+ });
2467
+ return Number(BigInt(result[0]));
2468
+ }
2469
+ /** Get the ERC-20 token address for a VM31 asset ID */
2470
+ async getAssetToken(assetId) {
2471
+ const result = await this.obelysk.provider.callContract({
2472
+ contractAddress: this.contractAddress,
2473
+ entrypoint: "get_asset_token",
2474
+ calldata: [assetId.toString()]
2475
+ });
2476
+ return result[0];
2477
+ }
2478
+ /** Get the VM31 asset ID for a given ERC-20 token address */
2479
+ async getTokenAsset(tokenAddress) {
2480
+ const result = await this.obelysk.provider.callContract({
2481
+ contractAddress: this.contractAddress,
2482
+ entrypoint: "get_token_asset",
2483
+ calldata: [tokenAddress]
2484
+ });
2485
+ return Number(BigInt(result[0]));
2486
+ }
2487
+ /** Check if the VM31Pool contract is paused */
2488
+ async isPaused() {
2489
+ const result = await this.obelysk.provider.callContract({
2490
+ contractAddress: this.contractAddress,
2491
+ entrypoint: "is_paused",
2492
+ calldata: []
2493
+ });
2494
+ return BigInt(result[0]) !== 0n;
2495
+ }
2496
+ /** Get the contract owner address */
2497
+ async getOwner() {
2498
+ const result = await this.obelysk.provider.callContract({
2499
+ contractAddress: this.contractAddress,
2500
+ entrypoint: "get_owner",
2501
+ calldata: []
2502
+ });
2503
+ return result[0];
2504
+ }
2505
+ /** Get the authorized relayer address */
2506
+ async getRelayer() {
2507
+ const result = await this.obelysk.provider.callContract({
2508
+ contractAddress: this.contractAddress,
2509
+ entrypoint: "get_relayer",
2510
+ calldata: []
2511
+ });
2512
+ return result[0];
2513
+ }
2514
+ /** Get batch timeout in blocks */
2515
+ async getBatchTimeoutBlocks() {
2516
+ const result = await this.obelysk.provider.callContract({
2517
+ contractAddress: this.contractAddress,
2518
+ entrypoint: "get_batch_timeout_blocks",
2519
+ calldata: []
2520
+ });
2521
+ return Number(BigInt(result[0]));
2522
+ }
2523
+ // --------------------------------------------------------------------------
2524
+ // Relayer HTTP calls
2525
+ // --------------------------------------------------------------------------
2526
+ /** Check relayer health (no auth required) */
2527
+ async getRelayerHealth() {
2528
+ return this.relayerFetch("/health");
2529
+ }
2530
+ /** Get relayer queue status */
2531
+ async getRelayerStatus() {
2532
+ const data = await this.relayerFetch("/status");
2533
+ return {
2534
+ pendingTransactions: data.pending_transactions,
2535
+ batchMaxSize: data.batch_max_size,
2536
+ batchTimeoutSecs: data.batch_timeout_secs
2537
+ };
2538
+ }
2539
+ /** Get the relayer's public encryption key */
2540
+ async getRelayerPublicKey() {
2541
+ const data = await this.relayerFetch("/public-key");
2542
+ return {
2543
+ publicKey: data.public_key,
2544
+ version: data.version,
2545
+ algorithm: data.algorithm
2546
+ };
2547
+ }
2548
+ /**
2549
+ * Submit a deposit transaction to the relayer.
2550
+ * Validates denomination (privacy gap #7) and encrypts with ECIES by default.
2551
+ * @param encrypt - Set to false for legacy plaintext mode (default: true)
2552
+ */
2553
+ async submitDeposit(params, encrypt = true) {
2554
+ validateDenomination(params.amount, params.assetId);
2555
+ return this.relayerSubmit({
2556
+ type: "deposit",
2557
+ amount: Number(params.amount),
2558
+ asset_id: params.assetId,
2559
+ recipient_pubkey: params.recipientPubkey,
2560
+ recipient_viewing_key: params.recipientViewingKey
2561
+ }, encrypt);
2562
+ }
2563
+ /**
2564
+ * Submit a withdrawal transaction to the relayer.
2565
+ * Withdrawals are not denomination-restricted.
2566
+ * @param encrypt - Set to false for legacy plaintext mode (default: true)
2567
+ */
2568
+ async submitWithdraw(params, encrypt = true) {
2569
+ return this.relayerSubmit({
2570
+ type: "withdraw",
2571
+ amount: Number(params.amount),
2572
+ asset_id: params.assetId,
2573
+ note: {
2574
+ owner_pubkey: params.note.owner_pubkey,
2575
+ asset_id: params.note.asset_id,
2576
+ amount_lo: params.note.amount_lo,
2577
+ amount_hi: params.note.amount_hi,
2578
+ blinding: params.note.blinding
2579
+ },
2580
+ spending_key: params.spendingKey,
2581
+ merkle_path: params.merklePath,
2582
+ merkle_root: params.merkleRoot,
2583
+ withdrawal_binding: params.withdrawalBinding,
2584
+ binding_salt: params.bindingSalt
2585
+ }, encrypt);
2586
+ }
2587
+ /**
2588
+ * Submit a private transfer transaction to the relayer.
2589
+ * Transfers are not denomination-restricted.
2590
+ * @param encrypt - Set to false for legacy plaintext mode (default: true)
2591
+ */
2592
+ async submitTransfer(params, encrypt = true) {
2593
+ return this.relayerSubmit({
2594
+ type: "transfer",
2595
+ amount: Number(params.amount),
2596
+ asset_id: params.assetId,
2597
+ recipient_pubkey: params.recipientPubkey,
2598
+ recipient_viewing_key: params.recipientViewingKey,
2599
+ sender_viewing_key: params.senderViewingKey,
2600
+ input_notes: params.inputNotes.map((n) => ({
2601
+ note: n.note,
2602
+ spending_key: n.spendingKey,
2603
+ merkle_path: n.merklePath
2604
+ })),
2605
+ merkle_root: params.merkleRoot
2606
+ }, encrypt);
2607
+ }
2608
+ /** Query batch info from the relayer */
2609
+ async queryBatch(batchId) {
2610
+ const data = await this.relayerFetch(`/batch/${batchId}`);
2611
+ return {
2612
+ id: data.id,
2613
+ status: data.status,
2614
+ txCount: data.tx_count,
2615
+ proofHash: data.proof_hash,
2616
+ batchIdOnchain: data.batch_id_onchain,
2617
+ txHash: data.tx_hash,
2618
+ createdAt: data.created_at,
2619
+ error: data.error
2620
+ };
2621
+ }
2622
+ /** Fetch Merkle path for a commitment from the relayer */
2623
+ async fetchMerklePath(commitment) {
2624
+ const data = await this.relayerFetch(`/merkle-path/${commitment}`);
2625
+ return {
2626
+ commitment: data.commitment,
2627
+ merklePath: data.merkle_path ?? null,
2628
+ merkleRoot: data.merkle_root ?? null,
2629
+ batchId: data.batch_id ?? null,
2630
+ createdAt: data.created_at,
2631
+ status: data.status
2632
+ };
2633
+ }
2634
+ /** Force the relayer to prove the current batch immediately */
2635
+ async forceProve() {
2636
+ const data = await this.relayerFetch("/prove", { method: "POST" });
2637
+ return {
2638
+ status: data.status,
2639
+ batchId: data.batch_id
2640
+ };
2641
+ }
2642
+ // --------------------------------------------------------------------------
2643
+ // Helpers
2644
+ // --------------------------------------------------------------------------
2645
+ /** Encode a bigint amount into M31 lo/hi pair (31-bit limbs) */
2646
+ static encodeAmountM31(amount) {
2647
+ const lo = Number(amount & 0x7FFFFFFFn);
2648
+ const hi = Number(amount >> 31n);
2649
+ return { lo, hi };
2650
+ }
2651
+ /** Decode an M31 lo/hi pair back into a bigint amount */
2652
+ static decodeAmountM31(lo, hi) {
2653
+ return BigInt(lo) + BigInt(hi) * (1n << 31n);
2654
+ }
2655
+ };
2656
+
2657
+ // src/obelysk/vm31Bridge.ts
2658
+ var VM31BridgeClient = class {
2659
+ constructor(obelysk) {
2660
+ this.obelysk = obelysk;
2661
+ }
2662
+ get contractAddress() {
2663
+ return this.obelysk.contracts.vm31_bridge;
2664
+ }
2665
+ /** Get the authorized relayer address */
2666
+ async getRelayer() {
2667
+ const result = await this.obelysk.provider.callContract({
2668
+ contractAddress: this.contractAddress,
2669
+ entrypoint: "get_relayer",
2670
+ calldata: []
2671
+ });
2672
+ return result[0];
2673
+ }
2674
+ /** Get the VM31Pool contract address */
2675
+ async getVM31Pool() {
2676
+ const result = await this.obelysk.provider.callContract({
2677
+ contractAddress: this.contractAddress,
2678
+ entrypoint: "get_vm31_pool",
2679
+ calldata: []
2680
+ });
2681
+ return result[0];
2682
+ }
2683
+ /** Get the ConfidentialTransfer contract address */
2684
+ async getConfidentialTransfer() {
2685
+ const result = await this.obelysk.provider.callContract({
2686
+ contractAddress: this.contractAddress,
2687
+ entrypoint: "get_confidential_transfer",
2688
+ calldata: []
2689
+ });
2690
+ return result[0];
2691
+ }
2692
+ /** Get the asset pair mapping for a given token address */
2693
+ async getAssetPair(tokenAddress) {
2694
+ try {
2695
+ const result = await this.obelysk.provider.callContract({
2696
+ contractAddress: this.contractAddress,
2697
+ entrypoint: "get_asset_pair",
2698
+ calldata: [tokenAddress]
2699
+ });
2700
+ return {
2701
+ vm31AssetId: result[0],
2702
+ confidentialAssetId: result[1]
2703
+ };
2704
+ } catch {
2705
+ return null;
2706
+ }
2707
+ }
2708
+ /** Check if a bridge key has already been processed */
2709
+ async isBridgeKeyProcessed(bridgeKey) {
2710
+ const result = await this.obelysk.provider.callContract({
2711
+ contractAddress: this.contractAddress,
2712
+ entrypoint: "is_bridge_key_processed",
2713
+ calldata: [bridgeKey]
2714
+ });
2715
+ return BigInt(result[0]) !== 0n;
2716
+ }
2717
+ /** Compute a bridge key from withdrawal parameters */
2718
+ async computeBridgeKey(params) {
2719
+ const low = params.amount & (1n << 128n) - 1n;
2720
+ const high = params.amount >> 128n;
2721
+ const result = await this.obelysk.provider.callContract({
2722
+ contractAddress: this.contractAddress,
2723
+ entrypoint: "compute_bridge_key",
2724
+ calldata: [
2725
+ params.batchId,
2726
+ params.withdrawalIdx.toString(),
2727
+ params.payoutRecipient,
2728
+ params.creditRecipient,
2729
+ params.token,
2730
+ low.toString(),
2731
+ high.toString()
2732
+ ]
2733
+ });
2734
+ return result[0];
2735
+ }
2736
+ /** Get full bridge configuration (relayer, vm31Pool, confidentialTransfer) */
2737
+ async getConfig() {
2738
+ const [relayer, vm31Pool, confidentialTransfer] = await Promise.all([
2739
+ this.getRelayer(),
2740
+ this.getVM31Pool(),
2741
+ this.getConfidentialTransfer()
2742
+ ]);
2743
+ return { relayer, vm31Pool, confidentialTransfer };
2744
+ }
2745
+ /** Get pending upgrade info, if any */
2746
+ async getPendingUpgrade() {
2747
+ const result = await this.obelysk.provider.callContract({
2748
+ contractAddress: this.contractAddress,
2749
+ entrypoint: "get_pending_upgrade",
2750
+ calldata: []
2751
+ });
2752
+ const classHash = result[0];
2753
+ if (classHash === "0x0") return null;
2754
+ return {
2755
+ classHash,
2756
+ scheduledAt: Number(BigInt(result[1]))
2757
+ };
2758
+ }
2759
+ /** Check if the bridge contract is paused */
2760
+ async isPaused() {
2761
+ try {
2762
+ const result = await this.obelysk.provider.callContract({
2763
+ contractAddress: this.contractAddress,
2764
+ entrypoint: "is_paused",
2765
+ calldata: []
2766
+ });
2767
+ return BigInt(result[0]) !== 0n;
2768
+ } catch {
2769
+ return false;
2770
+ }
2771
+ }
2772
+ };
2773
+
2774
+ // src/obelysk/otcOrderbook.ts
2775
+ var OrderSide = /* @__PURE__ */ ((OrderSide2) => {
2776
+ OrderSide2[OrderSide2["Buy"] = 0] = "Buy";
2777
+ OrderSide2[OrderSide2["Sell"] = 1] = "Sell";
2778
+ return OrderSide2;
2779
+ })(OrderSide || {});
2780
+ var OrderType = /* @__PURE__ */ ((OrderType2) => {
2781
+ OrderType2[OrderType2["Limit"] = 0] = "Limit";
2782
+ OrderType2[OrderType2["Market"] = 1] = "Market";
2783
+ return OrderType2;
2784
+ })(OrderType || {});
2785
+ var OrderStatus = /* @__PURE__ */ ((OrderStatus2) => {
2786
+ OrderStatus2[OrderStatus2["Open"] = 0] = "Open";
2787
+ OrderStatus2[OrderStatus2["PartialFill"] = 1] = "PartialFill";
2788
+ OrderStatus2[OrderStatus2["Filled"] = 2] = "Filled";
2789
+ OrderStatus2[OrderStatus2["Cancelled"] = 3] = "Cancelled";
2790
+ OrderStatus2[OrderStatus2["Expired"] = 4] = "Expired";
2791
+ return OrderStatus2;
2792
+ })(OrderStatus || {});
2793
+ var U128_MASK = (1n << 128n) - 1n;
2794
+ function splitU256(value) {
2795
+ return {
2796
+ low: (value & U128_MASK).toString(),
2797
+ high: (value >> 128n).toString()
2798
+ };
2799
+ }
2800
+ function parseU256(result, offset) {
2801
+ return BigInt(result[offset]) + (BigInt(result[offset + 1]) << 128n);
2802
+ }
2803
+ var ORDER_SIDE_VALUES = [0 /* Buy */, 1 /* Sell */];
2804
+ var ORDER_TYPE_VALUES = [0 /* Limit */, 1 /* Market */];
2805
+ var ORDER_STATUS_VALUES = [
2806
+ 0 /* Open */,
2807
+ 1 /* PartialFill */,
2808
+ 2 /* Filled */,
2809
+ 3 /* Cancelled */,
2810
+ 4 /* Expired */
2811
+ ];
2812
+ var ORDER_FELT_COUNT = 15;
2813
+ function parseOrder(result, offset) {
2814
+ return {
2815
+ orderId: parseU256(result, offset),
2816
+ maker: result[offset + 2],
2817
+ pairId: Number(BigInt(result[offset + 3])),
2818
+ side: ORDER_SIDE_VALUES[Number(BigInt(result[offset + 4]))] ?? 0 /* Buy */,
2819
+ orderType: ORDER_TYPE_VALUES[Number(BigInt(result[offset + 5]))] ?? 0 /* Limit */,
2820
+ price: parseU256(result, offset + 6),
2821
+ amount: parseU256(result, offset + 8),
2822
+ remaining: parseU256(result, offset + 10),
2823
+ status: ORDER_STATUS_VALUES[Number(BigInt(result[offset + 12]))] ?? 0 /* Open */,
2824
+ createdAt: Number(BigInt(result[offset + 13])),
2825
+ expiresAt: Number(BigInt(result[offset + 14]))
2826
+ };
2827
+ }
2828
+ var TRADE_FELT_COUNT = 15;
2829
+ function parseTrade(result, offset) {
2830
+ return {
2831
+ tradeId: parseU256(result, offset),
2832
+ makerOrderId: parseU256(result, offset + 2),
2833
+ takerOrderId: parseU256(result, offset + 4),
2834
+ maker: result[offset + 6],
2835
+ taker: result[offset + 7],
2836
+ price: parseU256(result, offset + 8),
2837
+ amount: parseU256(result, offset + 10),
2838
+ quoteAmount: parseU256(result, offset + 12),
2839
+ executedAt: Number(BigInt(result[offset + 14]))
2840
+ };
2841
+ }
2842
+ var OTCOrderbookClient = class {
2843
+ constructor(obelysk) {
2844
+ this.obelysk = obelysk;
2845
+ }
2846
+ get contractAddress() {
2847
+ const addr = this.obelysk.contracts.otc_orderbook;
2848
+ if (!addr) throw new Error("OTC Orderbook contract not configured for this network");
2849
+ return addr;
2850
+ }
2851
+ // --------------------------------------------------------------------------
2852
+ // Write operations
2853
+ // --------------------------------------------------------------------------
2854
+ /**
2855
+ * Place a limit order on the orderbook.
2856
+ *
2857
+ * The contract handles internal matching against resting orders.
2858
+ * Returns the transaction hash.
2859
+ */
2860
+ async placeLimitOrder(params) {
2861
+ const account = this.obelysk.requireAccount();
2862
+ const { low: pLow, high: pHigh } = splitU256(params.price);
2863
+ const { low: aLow, high: aHigh } = splitU256(params.amount);
2864
+ const result = await account.execute([
2865
+ {
2866
+ contractAddress: this.contractAddress,
2867
+ entrypoint: "place_limit_order",
2868
+ calldata: [
2869
+ params.pairId.toString(),
2870
+ params.side.toString(),
2871
+ pLow,
2872
+ pHigh,
2873
+ aLow,
2874
+ aHigh,
2875
+ (params.expiresIn ?? 0).toString()
2876
+ ]
2877
+ }
2878
+ ]);
2879
+ return result.transaction_hash;
2880
+ }
2881
+ /**
2882
+ * Place a market order that fills immediately against resting liquidity.
2883
+ * Returns the transaction hash.
2884
+ */
2885
+ async placeMarketOrder(params) {
2886
+ const account = this.obelysk.requireAccount();
2887
+ const { low: aLow, high: aHigh } = splitU256(params.amount);
2888
+ const result = await account.execute([
2889
+ {
2890
+ contractAddress: this.contractAddress,
2891
+ entrypoint: "place_market_order",
2892
+ calldata: [
2893
+ params.pairId.toString(),
2894
+ params.side.toString(),
2895
+ aLow,
2896
+ aHigh
2897
+ ]
2898
+ }
2899
+ ]);
2900
+ return result.transaction_hash;
2901
+ }
2902
+ /**
2903
+ * Cancel a single order by ID.
2904
+ * Only the maker can cancel their own order.
2905
+ */
2906
+ async cancelOrder(orderId) {
2907
+ const account = this.obelysk.requireAccount();
2908
+ const { low, high } = splitU256(orderId);
2909
+ const result = await account.execute([
2910
+ {
2911
+ contractAddress: this.contractAddress,
2912
+ entrypoint: "cancel_order",
2913
+ calldata: [low, high]
2914
+ }
2915
+ ]);
2916
+ return result.transaction_hash;
2917
+ }
2918
+ /**
2919
+ * Cancel all open orders for the caller.
2920
+ */
2921
+ async cancelAllOrders() {
2922
+ const account = this.obelysk.requireAccount();
2923
+ const result = await account.execute([
2924
+ {
2925
+ contractAddress: this.contractAddress,
2926
+ entrypoint: "cancel_all_orders",
2927
+ calldata: []
2928
+ }
2929
+ ]);
2930
+ return result.transaction_hash;
2931
+ }
2932
+ /**
2933
+ * Place multiple limit orders in a single transaction.
2934
+ *
2935
+ * Cairo expects an array of (u8, OrderSide, u256, u256, u64) tuples.
2936
+ * Calldata: [length, ...flattened orders].
2937
+ */
2938
+ async batchPlaceOrders(orders) {
2939
+ const account = this.obelysk.requireAccount();
2940
+ const calldata = [orders.length.toString()];
2941
+ for (const order of orders) {
2942
+ const { low: pLow, high: pHigh } = splitU256(order.price);
2943
+ const { low: aLow, high: aHigh } = splitU256(order.amount);
2944
+ calldata.push(
2945
+ order.pairId.toString(),
2946
+ order.side.toString(),
2947
+ pLow,
2948
+ pHigh,
2949
+ aLow,
2950
+ aHigh,
2951
+ (order.expiresIn ?? 0).toString()
2952
+ );
2953
+ }
2954
+ const result = await account.execute([
2955
+ {
2956
+ contractAddress: this.contractAddress,
2957
+ entrypoint: "batch_place_orders",
2958
+ calldata
2959
+ }
2960
+ ]);
2961
+ return result.transaction_hash;
2962
+ }
2963
+ /**
2964
+ * Cancel multiple orders in a single transaction.
2965
+ *
2966
+ * Calldata: [length, ...flattened u256 order IDs].
2967
+ */
2968
+ async batchCancelOrders(orderIds) {
2969
+ const account = this.obelysk.requireAccount();
2970
+ const calldata = [orderIds.length.toString()];
2971
+ for (const id of orderIds) {
2972
+ const { low, high } = splitU256(id);
2973
+ calldata.push(low, high);
2974
+ }
2975
+ const result = await account.execute([
2976
+ {
2977
+ contractAddress: this.contractAddress,
2978
+ entrypoint: "batch_cancel_orders",
2979
+ calldata
2980
+ }
2981
+ ]);
2982
+ return result.transaction_hash;
2983
+ }
2984
+ // --------------------------------------------------------------------------
2985
+ // Read operations
2986
+ // --------------------------------------------------------------------------
2987
+ /**
2988
+ * Get a single order by ID.
2989
+ */
2990
+ async getOrder(orderId) {
2991
+ const { low, high } = splitU256(orderId);
2992
+ const result = await this.obelysk.provider.callContract({
2993
+ contractAddress: this.contractAddress,
2994
+ entrypoint: "get_order",
2995
+ calldata: [low, high]
2996
+ });
2997
+ return parseOrder(result, 0);
2998
+ }
2999
+ /**
3000
+ * Get all order IDs belonging to a user.
3001
+ */
3002
+ async getUserOrders(user) {
3003
+ const result = await this.obelysk.provider.callContract({
3004
+ contractAddress: this.contractAddress,
3005
+ entrypoint: "get_user_orders",
3006
+ calldata: [user]
3007
+ });
3008
+ const len = Number(BigInt(result[0]));
3009
+ const ids = [];
3010
+ for (let i = 0; i < len; i++) {
3011
+ ids.push(parseU256(result, 1 + i * 2));
3012
+ }
3013
+ return ids;
3014
+ }
3015
+ /**
3016
+ * Get the best (highest) bid price for a trading pair.
3017
+ */
3018
+ async getBestBid(pairId) {
3019
+ const result = await this.obelysk.provider.callContract({
3020
+ contractAddress: this.contractAddress,
3021
+ entrypoint: "get_best_bid",
3022
+ calldata: [pairId.toString()]
3023
+ });
3024
+ return parseU256(result, 0);
3025
+ }
3026
+ /**
3027
+ * Get the best (lowest) ask price for a trading pair.
3028
+ */
3029
+ async getBestAsk(pairId) {
3030
+ const result = await this.obelysk.provider.callContract({
3031
+ contractAddress: this.contractAddress,
3032
+ entrypoint: "get_best_ask",
3033
+ calldata: [pairId.toString()]
3034
+ });
3035
+ return parseU256(result, 0);
3036
+ }
3037
+ /**
3038
+ * Get the bid-ask spread for a trading pair.
3039
+ */
3040
+ async getSpread(pairId) {
3041
+ const result = await this.obelysk.provider.callContract({
3042
+ contractAddress: this.contractAddress,
3043
+ entrypoint: "get_spread",
3044
+ calldata: [pairId.toString()]
3045
+ });
3046
+ return parseU256(result, 0);
3047
+ }
3048
+ /**
3049
+ * Get trading pair configuration.
3050
+ */
3051
+ async getPair(pairId) {
3052
+ const result = await this.obelysk.provider.callContract({
3053
+ contractAddress: this.contractAddress,
3054
+ entrypoint: "get_pair",
3055
+ calldata: [pairId.toString()]
3056
+ });
3057
+ return {
3058
+ baseToken: result[0],
3059
+ quoteToken: result[1],
3060
+ minOrderSize: parseU256(result, 2),
3061
+ tickSize: parseU256(result, 4),
3062
+ isActive: BigInt(result[6]) !== 0n
3063
+ };
3064
+ }
3065
+ /**
3066
+ * Get the orderbook configuration (fees, limits, pause state).
3067
+ */
3068
+ async getConfig() {
3069
+ const result = await this.obelysk.provider.callContract({
3070
+ contractAddress: this.contractAddress,
3071
+ entrypoint: "get_config",
3072
+ calldata: []
3073
+ });
3074
+ return {
3075
+ makerFeeBps: Number(BigInt(result[0])),
3076
+ takerFeeBps: Number(BigInt(result[1])),
3077
+ defaultExpirySecs: Number(BigInt(result[2])),
3078
+ maxOrdersPerUser: Number(BigInt(result[3])),
3079
+ paused: BigInt(result[4]) !== 0n
3080
+ };
3081
+ }
3082
+ /**
3083
+ * Get aggregate orderbook statistics.
3084
+ */
3085
+ async getStats() {
3086
+ const result = await this.obelysk.provider.callContract({
3087
+ contractAddress: this.contractAddress,
3088
+ entrypoint: "get_stats",
3089
+ calldata: []
3090
+ });
3091
+ return {
3092
+ orderCount: parseU256(result, 0),
3093
+ tradeCount: parseU256(result, 2),
3094
+ totalVolume: parseU256(result, 4),
3095
+ totalFees: parseU256(result, 6)
3096
+ };
3097
+ }
3098
+ /**
3099
+ * Get total number of orders ever placed.
3100
+ */
3101
+ async getOrderCount() {
3102
+ const result = await this.obelysk.provider.callContract({
3103
+ contractAddress: this.contractAddress,
3104
+ entrypoint: "get_order_count",
3105
+ calldata: []
3106
+ });
3107
+ return parseU256(result, 0);
3108
+ }
3109
+ /**
3110
+ * Get total number of trades executed.
3111
+ */
3112
+ async getTradeCount() {
3113
+ const result = await this.obelysk.provider.callContract({
3114
+ contractAddress: this.contractAddress,
3115
+ entrypoint: "get_trade_count",
3116
+ calldata: []
3117
+ });
3118
+ return parseU256(result, 0);
3119
+ }
3120
+ /**
3121
+ * Get the time-weighted average price for a trading pair.
3122
+ */
3123
+ async getTwap(pairId) {
3124
+ const result = await this.obelysk.provider.callContract({
3125
+ contractAddress: this.contractAddress,
3126
+ entrypoint: "get_twap",
3127
+ calldata: [pairId.toString()]
3128
+ });
3129
+ return parseU256(result, 0);
3130
+ }
3131
+ /**
3132
+ * Get 24-hour rolling statistics for a trading pair.
3133
+ */
3134
+ async get24hStats(pairId) {
3135
+ const result = await this.obelysk.provider.callContract({
3136
+ contractAddress: this.contractAddress,
3137
+ entrypoint: "get_24h_stats",
3138
+ calldata: [pairId.toString()]
3139
+ });
3140
+ return {
3141
+ volume: parseU256(result, 0),
3142
+ high: parseU256(result, 2),
3143
+ low: parseU256(result, 4),
3144
+ tradeCount: parseU256(result, 6)
3145
+ };
3146
+ }
3147
+ /**
3148
+ * Get the most recent trade for a trading pair.
3149
+ */
3150
+ async getLastTrade(pairId) {
3151
+ const result = await this.obelysk.provider.callContract({
3152
+ contractAddress: this.contractAddress,
3153
+ entrypoint: "get_last_trade",
3154
+ calldata: [pairId.toString()]
3155
+ });
3156
+ return {
3157
+ price: parseU256(result, 0),
3158
+ amount: parseU256(result, 2),
3159
+ timestamp: Number(BigInt(result[4]))
3160
+ };
3161
+ }
3162
+ /**
3163
+ * Get the orderbook depth (price levels) for a trading pair.
3164
+ *
3165
+ * Returns up to `maxLevels` aggregated price levels for both
3166
+ * bids and asks. Each level contains price, total amount, and
3167
+ * number of orders at that price.
3168
+ */
3169
+ async getOrderbookDepth(pairId, maxLevels) {
3170
+ const result = await this.obelysk.provider.callContract({
3171
+ contractAddress: this.contractAddress,
3172
+ entrypoint: "get_orderbook_depth",
3173
+ calldata: [pairId.toString(), maxLevels.toString()]
3174
+ });
3175
+ let offset = 0;
3176
+ const bidCount = Number(BigInt(result[offset]));
3177
+ offset += 1;
3178
+ const bids = [];
3179
+ for (let i = 0; i < bidCount; i++) {
3180
+ bids.push({
3181
+ price: parseU256(result, offset),
3182
+ totalAmount: parseU256(result, offset + 2),
3183
+ orderCount: Number(BigInt(result[offset + 4]))
3184
+ });
3185
+ offset += 5;
3186
+ }
3187
+ const askCount = Number(BigInt(result[offset]));
3188
+ offset += 1;
3189
+ const asks = [];
3190
+ for (let i = 0; i < askCount; i++) {
3191
+ asks.push({
3192
+ price: parseU256(result, offset),
3193
+ totalAmount: parseU256(result, offset + 2),
3194
+ orderCount: Number(BigInt(result[offset + 4]))
3195
+ });
3196
+ offset += 5;
3197
+ }
3198
+ return { bids, asks };
3199
+ }
3200
+ /**
3201
+ * Get active orders for a trading pair with pagination.
3202
+ */
3203
+ async getActiveOrders(pairId, offset, limit) {
3204
+ const result = await this.obelysk.provider.callContract({
3205
+ contractAddress: this.contractAddress,
3206
+ entrypoint: "get_active_orders",
3207
+ calldata: [pairId.toString(), offset.toString(), limit.toString()]
3208
+ });
3209
+ const len = Number(BigInt(result[0]));
3210
+ const orders = [];
3211
+ for (let i = 0; i < len; i++) {
3212
+ orders.push(parseOrder(result, 1 + i * ORDER_FELT_COUNT));
3213
+ }
3214
+ return orders;
3215
+ }
3216
+ /**
3217
+ * Get trade history for a trading pair with pagination.
3218
+ */
3219
+ async getTradeHistory(pairId, offset, limit) {
3220
+ const result = await this.obelysk.provider.callContract({
3221
+ contractAddress: this.contractAddress,
3222
+ entrypoint: "get_trade_history",
3223
+ calldata: [pairId.toString(), offset.toString(), limit.toString()]
3224
+ });
3225
+ const len = Number(BigInt(result[0]));
3226
+ const trades = [];
3227
+ for (let i = 0; i < len; i++) {
3228
+ trades.push(parseTrade(result, 1 + i * TRADE_FELT_COUNT));
3229
+ }
3230
+ return trades;
3231
+ }
3232
+ /**
3233
+ * Get the contract owner address.
3234
+ */
3235
+ async getOwner() {
3236
+ const result = await this.obelysk.provider.callContract({
3237
+ contractAddress: this.contractAddress,
3238
+ entrypoint: "owner",
3239
+ calldata: []
3240
+ });
3241
+ return result[0];
3242
+ }
1662
3243
  };
1663
3244
 
1664
3245
  // src/obelysk/client.ts
@@ -1670,6 +3251,8 @@ var ObelyskClient = class {
1670
3251
  contracts;
1671
3252
  tokens;
1672
3253
  privacyPools;
3254
+ relayerUrl;
3255
+ relayerApiKey;
1673
3256
  /** Privacy Pool operations (deposit/withdraw shielded tokens) */
1674
3257
  privacyPool;
1675
3258
  /** DarkPool batch auction trading */
@@ -1684,6 +3267,12 @@ var ObelyskClient = class {
1684
3267
  router;
1685
3268
  /** Shielded swap router (privacy-preserving AMM swaps) */
1686
3269
  swap;
3270
+ /** VM31 UTXO privacy vault (deposits/withdrawals/transfers via relayer) */
3271
+ vm31;
3272
+ /** VM31 confidential bridge (bridge VM31 withdrawals to encrypted balances) */
3273
+ bridge;
3274
+ /** OTC orderbook (limit/market orders, trade history) */
3275
+ otc;
1687
3276
  constructor(config) {
1688
3277
  this.network = config.network;
1689
3278
  this.provider = new import_starknet7.RpcProvider({ nodeUrl: config.rpcUrl ?? getRpcUrl(config.network) });
@@ -1691,6 +3280,8 @@ var ObelyskClient = class {
1691
3280
  this.contracts = getContracts(config.network);
1692
3281
  this.tokens = this.contracts.tokens ?? MAINNET_TOKENS;
1693
3282
  this.privacyPools = config.network === "mainnet" ? MAINNET_PRIVACY_POOLS : {};
3283
+ this.relayerUrl = config.relayerUrl;
3284
+ this.relayerApiKey = config.relayerApiKey;
1694
3285
  this.privacy = new ObelyskPrivacy();
1695
3286
  if (config.privacyPrivateKey) {
1696
3287
  const pk = BigInt(config.privacyPrivateKey);
@@ -1703,6 +3294,9 @@ var ObelyskClient = class {
1703
3294
  this.staking = new ProverStakingClient(this);
1704
3295
  this.router = new PrivacyRouterClient(this);
1705
3296
  this.swap = new ShieldedSwapClient(this);
3297
+ this.vm31 = new VM31VaultClient(this);
3298
+ this.bridge = new VM31BridgeClient(this);
3299
+ this.otc = new OTCOrderbookClient(this);
1706
3300
  }
1707
3301
  /** Get token address by symbol */
1708
3302
  getTokenAddress(symbol) {
@@ -1727,34 +3321,51 @@ var ObelyskClient = class {
1727
3321
  CURVE_ORDER,
1728
3322
  ConfidentialTransferClient,
1729
3323
  DARKPOOL_ASSET_IDS,
3324
+ DENOMINATION_BY_SYMBOL,
1730
3325
  DarkPoolClient,
3326
+ ETH_DENOMINATIONS,
1731
3327
  FIELD_PRIME,
1732
3328
  GENERATOR_G,
1733
3329
  GENERATOR_H,
1734
3330
  MAINNET_PRIVACY_POOLS,
1735
3331
  MAINNET_TOKENS,
3332
+ OTCOrderbookClient,
1736
3333
  ObelyskClient,
1737
3334
  ObelyskPrivacy,
3335
+ OrderSide,
3336
+ OrderStatus,
3337
+ OrderType,
1738
3338
  PrivacyPoolClient,
1739
3339
  PrivacyRouterClient,
1740
3340
  ProverStakingClient,
3341
+ SAGE_DENOMINATIONS,
3342
+ STRK_DENOMINATIONS,
1741
3343
  ShieldedSwapClient,
1742
3344
  StealthClient,
1743
3345
  TOKEN_DECIMALS,
3346
+ USDC_DENOMINATIONS,
3347
+ VM31BridgeClient,
3348
+ VM31VaultClient,
1744
3349
  VM31_ASSET_IDS,
3350
+ VM31_DENOMINATIONS,
3351
+ WBTC_DENOMINATIONS,
1745
3352
  commitmentToHash,
1746
3353
  createAEHint,
1747
3354
  createEncryptionProof,
1748
3355
  deriveNullifier,
1749
3356
  ecAdd,
1750
3357
  ecMul,
3358
+ eciesEncrypt,
1751
3359
  elgamalEncrypt,
1752
3360
  formatAmount,
1753
3361
  getContracts,
3362
+ getDenominations,
1754
3363
  getRpcUrl,
1755
3364
  mod,
1756
3365
  modInverse,
1757
3366
  parseAmount,
1758
3367
  pedersenCommit,
1759
- randomScalar
3368
+ randomScalar,
3369
+ splitIntoDenominations,
3370
+ validateDenomination
1760
3371
  });