@@ -33,55 +33,6 @@ import {
3333const RANGE_PROOF_WASM_URL =
3434 ' https://unpkg.com/@distributedlab/aptos-wasm-bindings@0.3.16/range-proofs/aptos_rp_wasm_bg.wasm'
3535
36- /**
37- * Generate range Zero Knowledge Proof
38- *
39- * @param opts.v The value to create the range proof for
40- * @param opts.r A vector of bytes representing the blinding scalar used to hide the value.
41- * @param opts.valBase A vector of bytes representing the generator point for the value.
42- * @param opts.randBase A vector of bytes representing the generator point for the randomness.
43- * @param opts.bits Bits size of value to create the range proof
44- */
45- export async function generateRangeZKP(
46- opts : RangeProofInputs ,
47- ): Promise <{ proof: Uint8Array ; commitment: Uint8Array }> {
48- await initWasm ({ module_or_path: RANGE_PROOF_WASM_URL })
49-
50- const proof = rangeProof (
51- opts .v ,
52- opts .r ,
53- opts .valBase ,
54- opts .randBase ,
55- opts .bits ?? 32 ,
56- )
57-
58- return {
59- proof: proof .proof (),
60- commitment: proof .comm (),
61- }
62- }
63-
64- /**
65- * Verify range Zero Knowledge Proof
66- *
67- * @param opts.proof A vector of bytes representing the serialized range proof to be verified.
68- * @param opts.commitment A vector of bytes representing the Pedersen commitment the range proof is generated for.
69- * @param opts.valBase A vector of bytes representing the generator point for the value.
70- * @param opts.randBase A vector of bytes representing the generator point for the randomness.
71- * @param opts.bits Bits size of the value for range proof
72- */
73- export async function verifyRangeZKP(opts : VerifyRangeProofInputs ) {
74- await initWasm ({ module_or_path: RANGE_PROOF_WASM_URL })
75-
76- return verifyProof (
77- opts .proof ,
78- opts .commitment ,
79- opts .valBase ,
80- opts .randBase ,
81- opts .bits ?? 32 ,
82- )
83- }
84-
8536export async function genBatchRangeZKP(
8637 opts : BatchRangeProofInputs ,
8738): Promise <{ proof: Uint8Array ; commitments: Uint8Array [] }> {
@@ -248,7 +199,7 @@ export const registerConfidentialBalance = async (
248199 publicKeyHex : string ,
249200 tokenAddress = " 0x..." ,
250201) => {
251- const txBody = await aptos .confidentialCoin .deposit ({
202+ const txBody = await aptos .confidentialAsset .deposit ({
252203 sender: account .accountAddress ,
253204 to: AccountAddress .from (to ),
254205 tokenAddress: tokenAddress ,
@@ -270,7 +221,7 @@ export const getIsAccountRegisteredWithToken = async (
270221 account : Account ,
271222 tokenAddress = " 0x..." ,
272223) => {
273- const isRegistered = await aptos .confidentialCoin .hasUserRegistered ({
224+ const isRegistered = await aptos .confidentialAsset .hasUserRegistered ({
274225 accountAddress: account .accountAddress ,
275226 tokenAddress: tokenAddress ,
276227 })
@@ -292,7 +243,7 @@ export const depositConfidentialBalance = async (
292243 to : string ,
293244 tokenAddress = " 0x..." ,
294245) => {
295- const txBody = await aptos .confidentialCoin .deposit ({
246+ const txBody = await aptos .confidentialAsset .deposit ({
296247 sender: account .accountAddress ,
297248 to: AccountAddress .from (to ),
298249 tokenAddress: tokenAddress ,
@@ -307,7 +258,7 @@ export const depositConfidentialBalance = async (
307258Let's check the user's balance after the deposit.
308259
309260``` typescript
310- const userConfidentialBalance = await aptos .confidentialCoin .getBalance ({ accountAddress: user .accountAddress , tokenAddress: TOKEN_ADDRESS });
261+ const userConfidentialBalance = await aptos .confidentialAsset .getBalance ({ accountAddress: user .accountAddress , tokenAddress: TOKEN_ADDRESS });
311262```
312263
313264This method returns you the user's [ ` pending ` and ` actual ` ] ( /en/build/smart-contracts/confidential-asset#confidential-asset-store ) confidential balances, and to [ decrypt] ( /en/build/smart-contracts/confidential-asset#encryption-and-decryption ) them, you can use ` ConfidentialAmount ` class
@@ -320,17 +271,15 @@ export const getConfidentialBalances = async (
320271) => {
321272 const decryptionKey = new TwistedEd25519PrivateKey (decryptionKeyHex )
322273
323- const { pending, actual } = await aptos .confidentialCoin .getBalance ({
274+ const { pending, actual } = await aptos .confidentialAsset .getBalance ({
324275 accountAddress: account .accountAddress ,
325276 tokenAddress ,
326277 })
327278
328279 try {
329280 const [confidentialAmountPending, confidentialAmountActual] =
330281 await Promise .all ([
331- ConfidentialAmount .fromEncrypted (pending , decryptionKey , {
332- chunksCount: ConfidentialAmount .CHUNKS_COUNT / 2 , // !important: user's pending balance chunks count is always half of actual
333- }),
282+ ConfidentialAmount .fromEncrypted (pending , decryptionKey ),
334283 ConfidentialAmount .fromEncrypted (actual , decryptionKey ),
335284 ])
336285
@@ -353,21 +302,21 @@ After you deposited to user's confidential balance, you can see, that he has, fo
353302
354303User can't operate with ` pending ` balance, so you could [ rollover] ( /en/build/smart-contracts/confidential-asset#rollover-pending-balance ) it to ` actual ` one.
355304
356- And to do so - use ` aptos.confidentialCoin .rolloverPendingBalance ` .
305+ And to do so - use ` aptos.confidentialAsset .rolloverPendingBalance ` .
357306
358307<Callout type = " warning" >
359308 Important note, that user's actual balance need to be [ normalized] ( /en/build/smart-contracts/confidential-asset#normalize ) before ` rollover ` operation.
360309</Callout >
361310
362- To cover [ normalization] ( #normalization ) & ` rollover ` simultaneously, you could use ` aptos.confidentialCoin .safeRolloverPendingCB ` .
311+ To cover [ normalization] ( #normalization ) & ` rollover ` simultaneously, you could use ` aptos.confidentialAsset .safeRolloverPendingCB ` .
363312
364313``` typescript
365314export const safelyRolloverConfidentialBalance = async (
366315 account : Account ,
367316 decryptionKeyHex : string ,
368317 tokenAddress = " 0x..." ,
369318) => {
370- const rolloverTxPayloads = await aptos .confidentialCoin .safeRolloverPendingCB ({
319+ const rolloverTxPayloads = await aptos .confidentialAsset .safeRolloverPendingCB ({
371320 sender: account .accountAddress ,
372321 tokenAddress ,
373322 decryptionKey: new TwistedEd25519PrivateKey (decryptionKeyHex ),
@@ -394,7 +343,7 @@ export const getIsBalanceNormalized = async (
394343 account : Account ,
395344 tokenAddress = " 0x..." ,
396345) => {
397- const isNormalized = await aptos .confidentialCoin .isUserBalanceNormalized ({
346+ const isNormalized = await aptos .confidentialAsset .isUserBalanceNormalized ({
398347 accountAddress: account .accountAddress ,
399348 tokenAddress: tokenAddress ,
400349 })
@@ -403,7 +352,7 @@ export const getIsBalanceNormalized = async (
403352}
404353```
405354
406- Get your balance and finally call the ` aptos.confidentialCoin .normalizeUserBalance ` method:
355+ Get your balance and finally call the ` aptos.confidentialAsset .normalizeUserBalance ` method:
407356
408357``` typescript
409358export const normalizeConfidentialBalance = async (
@@ -413,7 +362,7 @@ export const normalizeConfidentialBalance = async (
413362 amount : bigint ,
414363 tokenAddress = " 0x..." ,
415364) => {
416- const normalizeTx = await aptos .confidentialCoin .normalizeUserBalance ({
365+ const normalizeTx = await aptos .confidentialAsset .normalizeUserBalance ({
417366 tokenAddress ,
418367 decryptionKey: new TwistedEd25519PrivateKey (decryptionKeyHex ),
419368 unnormalizedEncryptedBalance: encryptedPendingBalance ,
@@ -439,7 +388,7 @@ export const withdrawConfidentialBalance = async (
439388 encryptedActualBalance : TwistedElGamalCiphertext [],
440389 tokenAddress = ' 0x...' ,
441390) => {
442- const withdrawTx = await aptos .confidentialCoin .withdraw ({
391+ const withdrawTx = await aptos .confidentialAsset .withdraw ({
443392 sender: account .accountAddress ,
444393 to: receiver ,
445394 tokenAddress ,
@@ -460,7 +409,7 @@ Let's say you have a recipient's account address, let's get their encryption key
460409
461410``` typescript
462411export const getEkByAddr = async (addrHex : string , tokenAddress : string ) => {
463- return aptos .confidentialCoin .getEncryptionByAddr ({
412+ return aptos .confidentialAsset .getEncryptionByAddr ({
464413 accountAddress: AccountAddress .from (addrHex ),
465414 tokenAddress ,
466415 })
@@ -486,7 +435,7 @@ export const transferConfidentialCoin = async (
486435 tokenAddress ,
487436 )
488437
489- const transferTx = await aptos .confidentialCoin .transferCoin ({
438+ const transferTx = await aptos .confidentialAsset .transferCoin ({
490439 senderDecryptionKey: decryptionKey ,
491440 recipientEncryptionKey: new TwistedEd25519PublicKey (
492441 recipientEncryptionKeyHex ,
@@ -507,14 +456,14 @@ export const transferConfidentialCoin = async (
507456
508457### Key Rotation
509458
510- To do [ key rotation] ( /en/build/smart-contracts/confidential-asset#rotate-encryption-key ) , you need to create a new decryption key and use ` aptos.confidentialCoin .rotateCBKey `
459+ To do [ key rotation] ( /en/build/smart-contracts/confidential-asset#rotate-encryption-key ) , you need to create a new decryption key and use ` aptos.confidentialAsset .rotateCBKey `
511460
512461<Callout type = " warning" >
513462 But keep in mind, that ` key-rotation ` checks that pending balance equals 0.
514463 In that case, we could do a ` rollover ` with ` freeze ` option, to move assets from the pending balance to the actual one and lock our balance.
515464
516465 ``` typescript
517- aptos .confidentialCoin .safeRolloverPendingCB ({
466+ aptos .confidentialAsset .safeRolloverPendingCB ({
518467 ... ,
519468 withFreezeBalance: false ,
520469 })
0 commit comments