h_test_1 0.0.42 → 0.0.45

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.
@@ -1 +1 @@
1
- const e=require(`../../../functions/utils/resolve-sync.utils.cjs`);var t=class{blockchainEventEmitter;eventName;constructor(e,t){this.blockchainEventEmitter=e,this.eventName=t,e.addEventProcessorFunction(this.processEventsPage.bind(this))}get latestBlockNumber(){return this.blockchainEventEmitter.latestBlockNumber}get chainId(){return this.blockchainEventEmitter.chainId}intervalClear(){this.blockchainEventEmitter.intervalClear()}async processEventsPage(t){let n=new Set;t.forEach(({eventName:e,transactionHash:t})=>{e===`BlockedUtxosCreated`&&n.add(t)});let r=[];await e.resolveSync(t.map(e=>async()=>{if(e.eventName!==this.eventName)return;let{blockNumber:t,transactionHash:i}=e,a=this.mapEvent(e),o=n.has(i);await this.acceptEvent(a,t,i,o)&&r.push(a)}));let i=r.length;return await this.afterEventsAccepted(i),r.length}};exports.AbstractEventService=t;
1
+ const e=require(`../../../functions/utils/resolve-sync.utils.cjs`);var t=class{blockchainEventEmitter;eventName;constructor(e,t){this.blockchainEventEmitter=e,this.eventName=t,e.addEventProcessorFunction(this.processEventsPage.bind(this))}get latestBlockNumber(){return this.blockchainEventEmitter.latestBlockNumber}get chainId(){return this.blockchainEventEmitter.chainId}intervalClear(){this.blockchainEventEmitter.intervalClear()}async processEventsPage(t){let n=new Set;t.forEach(({eventName:e,transactionHash:t})=>{e===`BlockedUtxosCreated`&&n.add(t)});let r=[];await e.resolveSync(t.map(e=>async()=>{if(e.eventName!==this.eventName)return;console.log(`NEW EVENT`,{event:e});let{blockNumber:t,transactionHash:i}=e,a=this.mapEvent(e),o=n.has(i);await this.acceptEvent(a,t,i,o)&&r.push(a)}));let i=r.length;return await this.afterEventsAccepted(i),r.length}};exports.AbstractEventService=t;
@@ -23,6 +23,7 @@ var t = class {
23
23
  let r = [];
24
24
  await e(t.map((e) => async () => {
25
25
  if (e.eventName !== this.eventName) return;
26
+ console.log("NEW EVENT", { event: e });
26
27
  let { blockNumber: t, transactionHash: i } = e, a = this.mapEvent(e), o = n.has(i);
27
28
  await this.acceptEvent(a, t, i, o) && r.push(a);
28
29
  }));
@@ -1 +1 @@
1
- require(`../../../_virtual/_rolldown/runtime.cjs`);const e=require(`../../../constants/chains.constants.cjs`),t=require(`../../utils/caseInsensitive.utils.cjs`),n=require(`../../utils/addresses.cjs`),r=require(`../../../API/scheduled-transactions-calls.cjs`),i=require(`../../../data-structures/utxo/Utxo.cjs`),a=require(`../../utils/upToDateState.cjs`),o=require(`../../utils/cacheFunctions.cjs`),s=require(`../../utils/encodeTokenWithId.cjs`),c=require(`../../utils/solanaMint.utils.cjs`),l=require(`./getInputUtxosEnclave.cjs`),u=require(`../../utils/tron.utils.cjs`);var d=new(require(`async-mutex`)).Mutex,f=async(e,t,n,r,i,s,c,l,u)=>d.runExclusive(async()=>{u+=1;let d=s.slice(u),{lastOutput:f,additionalEncryptedOutputs:p}=await e.utxoUtils.batchProcess(d,l,t,n),m=[...c,...p];return await a.checkAddressNotUpdated(e,r),o.setHinkalCache({lastOutput:f,encryptedOutputs:m},e,n,i),await e.utxoUtils.buildBatchProcess(m,t,n)}),p=async(e,t,n,r)=>{let{utxos:i,encryptedOutputs:a,lastOutput:s}=await l.getInputUtxosEnclave(e,n,t);return o.setHinkalCache({encryptedOutputs:a,lastOutput:s},e,n,r),i},m=async(e,t,n,r,i,a,o,s,c)=>{try{return await p(e,t,n,i)}catch{return f(e,t,n,r,i,a,o,s,c)}},h=e=>{if(Array.isArray(e))return e;if(e!==void 0)return[e]},g=async(e,t,n)=>await e.utxoUtils.batchFilterUtxosWithNullifier(t,n),_=(e,t,n,r,a,o,s)=>{for(e.sort((e,t)=>e.amount<=t.amount?1:-1);e.length<t||e.length>t&&e.length<6;)if(e.push(new i.Utxo({amount:0n,erc20TokenAddress:a,mintAddress:s,shieldedPrivateKey:r,tokenId:o})),n)for(;e.length>6;)e.splice(e.length-1)},v=async({hinkal:e,chainId:t,passedShieldedPublicKey:n=void 0,ethAddress:r=void 0,resetCacheBefore:i=!1,allowRemoteDecryption:s=!1,useBlockedUtxos:c=!1})=>{let l=r??await e.getEthereumAddress(),u=n??e.userKeys.getShieldedPublicKey(),{userKeys:d}=e,p=e.encryptedOutputsByChain[t],h=e.nullifiersByChain[t],_=Array.from(p);i&&o.resetCache(e,t,u);let{encryptedOutputs:v,lastOutput:y}=o.getHinkalCache(e,t,u);await a.checkAddressNotUpdated(e,l);let b=y!==``,x=_.findIndex(e=>e.value===y),S=x>-1,C=!b&&x===-1,w=e.areMerkleTreeUpdatesDisabled(),T=!w&&(S||!s&&C),E=!w&&s&&C,D=!T&&!E,O=[];T?O=await f(e,d,t,l,u,_,v,y,x):E?O=await m(e,d,t,l,u,_,v,y,x):D&&(O=await e.utxoUtils.buildBatchProcess(v,d,t)),await a.checkAddressNotUpdated(e,l);let k=await g(e,O,h);return{inputUtxos:c?k.filter(e=>e.isBlocked):k.filter(e=>!e.isBlocked)}},y=async({hinkal:t,chainId:i,passedShieldedPublicKey:a=void 0,ethAddress:o=void 0,resetCacheBefore:s=!1,allowRemoteDecryption:c=!1})=>{let l=o??await t.getEthereumAddressByChain(i),d=n.hashEthereumAddress(e.isTronLike(i)?u.addressToHexFormat(l):l),{inputUtxos:f}=await v({hinkal:t,chainId:i,passedShieldedPublicKey:a,ethAddress:l,resetCacheBefore:s,allowRemoteDecryption:c,useBlockedUtxos:!0});if(!f.length)return{inputUtxos:[]};let{indexes:p}=await r.getScheduledTransactionsNullifierIndexes({hashedEthereumAddress:d,nullifiers:f.map(e=>e.getNullifier())});return{inputUtxos:p.map(e=>f[e]).filter(e=>!!e)}},b=async({hinkal:n,tokenWithId:r,minInput:i=2,sliceIfMore6:a=!0,chainId:o,passedShieldedPrivateKey:l=void 0,passedShieldedPublicKey:u=void 0,ethAddress:d=void 0,resetCacheBefore:f=!1,ensuredTokensWithId:p,useBlockedUtxos:m=!1})=>{console.log(`getInputUtxoAndBalancePerToken 0 start`,{tokenWithId:r,minInput:i,sliceIfMore6:a,chainId:o,passedShieldedPrivateKey:l,passedShieldedPublicKey:u,ethAddress:d,resetCacheBefore:f,ensuredTokensWithId:p,useBlockedUtxos:m});let g=l??n.userKeys.getShieldedPrivateKey();console.log(`getInputUtxoAndBalancePerToken 1 useBlockedUtxos`,m);let{inputUtxos:b}=m?await y({hinkal:n,chainId:o,ethAddress:d,passedShieldedPrivateKey:l,resetCacheBefore:f}):await v({hinkal:n,tokenWithId:r,minInput:i,sliceIfMore6:a,chainId:o,passedShieldedPrivateKey:l,passedShieldedPublicKey:u,ethAddress:d,resetCacheBefore:f});console.log(`getInputUtxoAndBalancePerToken 2 inputUtxos`,b);let x=h(r);console.log(`getInputUtxoAndBalancePerToken 3 tokensWithId`,x);let S=new Map;b.forEach(e=>{let n=e.getTokenAddress(o);if(x&&!x.some(r=>t.caseInsensitiveEqual(r.erc20TokenAddress,n)&&r.tokenId===e.tokenId))return;let r=s.encodeTokenWithId(o,{erc20TokenAddress:n,tokenId:e.tokenId}),i=S.get(r)??[];S.set(r,[...i,e])}),console.log(`getInputUtxoAndBalancePerToken 4 inputUtxosPerToken`,S),p?.forEach(e=>{let t=s.encodeTokenWithId(o,{erc20TokenAddress:e.erc20TokenAddress,tokenId:e.tokenId});S.set(t,S.get(t)??[])}),console.log(`getInputUtxoAndBalancePerToken 5 ensuredTokensWithId`,p);for(let[t,n]of S){let r=t.split(`-`)[0],s=Number(t.split(`-`)[1]),l=e.isSolanaLike(o),u=l?r:void 0;_(n,i,a,g,l?c.formatMintAddress(r).compressedAddress.toLowerCase():r.toLowerCase(),s,u)}return console.log(`getInputUtxoAndBalancePerToken 6 inputUtxosPerToken`,S),S};exports.attemptGetInputUtxosRemotely=m,exports.getInputUtxoAndBalance=v,exports.getInputUtxoAndBalanceOfStuckUtxos=y,exports.getInputUtxoAndBalancePerToken=b,exports.getInputUtxosRemotely=p;
1
+ require(`../../../_virtual/_rolldown/runtime.cjs`);const e=require(`../../../constants/chains.constants.cjs`),t=require(`../../utils/caseInsensitive.utils.cjs`),n=require(`../../utils/addresses.cjs`),r=require(`../../../API/scheduled-transactions-calls.cjs`),i=require(`../../../data-structures/utxo/Utxo.cjs`),a=require(`../../utils/upToDateState.cjs`),o=require(`../../utils/cacheFunctions.cjs`),s=require(`../../utils/encodeTokenWithId.cjs`),c=require(`../../utils/solanaMint.utils.cjs`),l=require(`./getInputUtxosEnclave.cjs`),u=require(`../../utils/tron.utils.cjs`);var d=new(require(`async-mutex`)).Mutex,f=async(e,t,n,r,i,s,c,l,u)=>d.runExclusive(async()=>{u+=1;let d=s.slice(u),{lastOutput:f,additionalEncryptedOutputs:p}=await e.utxoUtils.batchProcess(d,l,t,n),m=[...c,...p];return await a.checkAddressNotUpdated(e,r),o.setHinkalCache({lastOutput:f,encryptedOutputs:m},e,n,i),await e.utxoUtils.buildBatchProcess(m,t,n)}),p=async(e,t,n,r)=>{let{utxos:i,encryptedOutputs:a,lastOutput:s}=await l.getInputUtxosEnclave(e,n,t);return o.setHinkalCache({encryptedOutputs:a,lastOutput:s},e,n,r),i},m=async(e,t,n,r,i,a,o,s,c)=>{try{return await p(e,t,n,i)}catch{return f(e,t,n,r,i,a,o,s,c)}},h=e=>{if(Array.isArray(e))return e;if(e!==void 0)return[e]},g=async(e,t,n)=>await e.utxoUtils.batchFilterUtxosWithNullifier(t,n),_=(e,t,n,r,a,o,s)=>{for(e.sort((e,t)=>e.amount<=t.amount?1:-1);e.length<t||e.length>t&&e.length<6;)if(e.push(new i.Utxo({amount:0n,erc20TokenAddress:a,mintAddress:s,shieldedPrivateKey:r,tokenId:o})),n)for(;e.length>6;)e.splice(e.length-1)},v=async({hinkal:e,chainId:t,passedShieldedPublicKey:n=void 0,ethAddress:r=void 0,resetCacheBefore:i=!1,allowRemoteDecryption:s=!1,useBlockedUtxos:c=!1})=>{let l=r??await e.getEthereumAddress(),u=n??e.userKeys.getShieldedPublicKey();console.log(`getInputUtxoAndBalance 0 start`,{chainId:t,ethereumAddress:l,shieldedPublicKey:u});let{userKeys:d}=e,p=e.encryptedOutputsByChain[t],h=e.nullifiersByChain[t],_=Array.from(p);console.log(`getInputUtxoAndBalance 2 hinkalOutputs`,{hinkalOutputs:_,encryptedOutputs:p,nullifiers:h}),i&&o.resetCache(e,t,u);let{encryptedOutputs:v,lastOutput:y}=o.getHinkalCache(e,t,u);console.log(`getInputUtxoAndBalance 1 cachedEncryptedOutputs`,{cachedEncryptedOutputs:v,lastOutput:y}),await a.checkAddressNotUpdated(e,l);let b=y!==``,x=_.findIndex(e=>e.value===y),S=x>-1,C=!b&&x===-1;console.log(`getInputUtxoAndBalance 3 case1`,S,C,b,x);let w=e.areMerkleTreeUpdatesDisabled(),T=!w&&(S||!s&&C),E=!w&&s&&C,D=!T&&!E;console.log(`getInputUtxoAndBalance 4 forceReadFromCache`,w),console.log(`getInputUtxoAndBalance 5 decryptLocally`,T),console.log(`getInputUtxoAndBalance 6 decryptRemotely`,E),console.log(`getInputUtxoAndBalance 7 useCache`,D);let O=[];T?O=await f(e,d,t,l,u,_,v,y,x):E?O=await m(e,d,t,l,u,_,v,y,x):D&&(O=await e.utxoUtils.buildBatchProcess(v,d,t)),console.log({allUtxos:O}),await a.checkAddressNotUpdated(e,l);let k=await g(e,O,h);console.log(`getInputUtxoAndBalance 8 inputUtxos`,k);let A=c?k.filter(e=>e.isBlocked):k.filter(e=>!e.isBlocked);return console.log(`getInputUtxoAndBalance 9 filteredInputUtxos`,A),{inputUtxos:A}},y=async({hinkal:t,chainId:i,passedShieldedPublicKey:a=void 0,ethAddress:o=void 0,resetCacheBefore:s=!1,allowRemoteDecryption:c=!1})=>{let l=o??await t.getEthereumAddressByChain(i),d=n.hashEthereumAddress(e.isTronLike(i)?u.addressToHexFormat(l):l),{inputUtxos:f}=await v({hinkal:t,chainId:i,passedShieldedPublicKey:a,ethAddress:l,resetCacheBefore:s,allowRemoteDecryption:c,useBlockedUtxos:!0});if(!f.length)return{inputUtxos:[]};let{indexes:p}=await r.getScheduledTransactionsNullifierIndexes({hashedEthereumAddress:d,nullifiers:f.map(e=>e.getNullifier())});return{inputUtxos:p.map(e=>f[e]).filter(e=>!!e)}},b=async({hinkal:n,tokenWithId:r,minInput:i=2,sliceIfMore6:a=!0,chainId:o,passedShieldedPrivateKey:l=void 0,passedShieldedPublicKey:u=void 0,ethAddress:d=void 0,resetCacheBefore:f=!1,ensuredTokensWithId:p,useBlockedUtxos:m=!1})=>{console.log(`getInputUtxoAndBalancePerToken 0 start`,{tokenWithId:r,minInput:i,sliceIfMore6:a,chainId:o,passedShieldedPrivateKey:l,passedShieldedPublicKey:u,ethAddress:d,resetCacheBefore:f,ensuredTokensWithId:p,useBlockedUtxos:m});let g=l??n.userKeys.getShieldedPrivateKey();console.log(`getInputUtxoAndBalancePerToken 1 useBlockedUtxos`,m);let{inputUtxos:b}=m?await y({hinkal:n,chainId:o,ethAddress:d,passedShieldedPrivateKey:l,resetCacheBefore:f}):await v({hinkal:n,tokenWithId:r,minInput:i,sliceIfMore6:a,chainId:o,passedShieldedPrivateKey:l,passedShieldedPublicKey:u,ethAddress:d,resetCacheBefore:f});console.log(`getInputUtxoAndBalancePerToken 2 inputUtxos`,b);let x=h(r);console.log(`getInputUtxoAndBalancePerToken 3 tokensWithId`,x);let S=new Map;b.forEach(e=>{let n=e.getTokenAddress(o);if(x&&!x.some(r=>t.caseInsensitiveEqual(r.erc20TokenAddress,n)&&r.tokenId===e.tokenId))return;let r=s.encodeTokenWithId(o,{erc20TokenAddress:n,tokenId:e.tokenId}),i=S.get(r)??[];S.set(r,[...i,e])}),console.log(`getInputUtxoAndBalancePerToken 4 inputUtxosPerToken`,S),p?.forEach(e=>{let t=s.encodeTokenWithId(o,{erc20TokenAddress:e.erc20TokenAddress,tokenId:e.tokenId});S.set(t,S.get(t)??[])}),console.log(`getInputUtxoAndBalancePerToken 5 ensuredTokensWithId`,p);for(let[t,n]of S){let r=t.split(`-`)[0],s=Number(t.split(`-`)[1]),l=e.isSolanaLike(o),u=l?r:void 0;_(n,i,a,g,l?c.formatMintAddress(r).compressedAddress.toLowerCase():r.toLowerCase(),s,u)}return console.log(`getInputUtxoAndBalancePerToken 6 inputUtxosPerToken`,S),S};exports.attemptGetInputUtxosRemotely=m,exports.getInputUtxoAndBalance=v,exports.getInputUtxoAndBalanceOfStuckUtxos=y,exports.getInputUtxoAndBalancePerToken=b,exports.getInputUtxosRemotely=p;
@@ -42,14 +42,33 @@ var h = new m(), g = async (e, t, n, r, i, a, s, c, u) => h.runExclusive(async (
42
42
  tokenId: o
43
43
  })), n) for (; e.length > 6;) e.splice(e.length - 1);
44
44
  }, S = async ({ hinkal: e, chainId: t, passedShieldedPublicKey: n = void 0, ethAddress: r = void 0, resetCacheBefore: i = !1, allowRemoteDecryption: a = !1, useBlockedUtxos: l = !1 }) => {
45
- let u = r ?? await e.getEthereumAddress(), d = n ?? e.userKeys.getShieldedPublicKey(), { userKeys: f } = e, p = e.encryptedOutputsByChain[t], m = e.nullifiersByChain[t], h = Array.from(p);
46
- i && c(e, t, d);
45
+ let u = r ?? await e.getEthereumAddress(), d = n ?? e.userKeys.getShieldedPublicKey();
46
+ console.log("getInputUtxoAndBalance 0 start", {
47
+ chainId: t,
48
+ ethereumAddress: u,
49
+ shieldedPublicKey: d
50
+ });
51
+ let { userKeys: f } = e, p = e.encryptedOutputsByChain[t], m = e.nullifiersByChain[t], h = Array.from(p);
52
+ console.log("getInputUtxoAndBalance 2 hinkalOutputs", {
53
+ hinkalOutputs: h,
54
+ encryptedOutputs: p,
55
+ nullifiers: m
56
+ }), i && c(e, t, d);
47
57
  let { encryptedOutputs: _, lastOutput: y } = s(e, t, d);
48
- await o(e, u);
49
- let x = y !== "", S = h.findIndex((e) => e.value === y), C = S > -1, w = !x && S === -1, T = e.areMerkleTreeUpdatesDisabled(), E = !T && (C || !a && w), D = !T && a && w, O = !E && !D, k = [];
50
- E ? k = await g(e, f, t, u, d, h, _, y, S) : D ? k = await v(e, f, t, u, d, h, _, y, S) : O && (k = await e.utxoUtils.buildBatchProcess(_, f, t)), await o(e, u);
58
+ console.log("getInputUtxoAndBalance 1 cachedEncryptedOutputs", {
59
+ cachedEncryptedOutputs: _,
60
+ lastOutput: y
61
+ }), await o(e, u);
62
+ let x = y !== "", S = h.findIndex((e) => e.value === y), C = S > -1, w = !x && S === -1;
63
+ console.log("getInputUtxoAndBalance 3 case1", C, w, x, S);
64
+ let T = e.areMerkleTreeUpdatesDisabled(), E = !T && (C || !a && w), D = !T && a && w, O = !E && !D;
65
+ console.log("getInputUtxoAndBalance 4 forceReadFromCache", T), console.log("getInputUtxoAndBalance 5 decryptLocally", E), console.log("getInputUtxoAndBalance 6 decryptRemotely", D), console.log("getInputUtxoAndBalance 7 useCache", O);
66
+ let k = [];
67
+ E ? k = await g(e, f, t, u, d, h, _, y, S) : D ? k = await v(e, f, t, u, d, h, _, y, S) : O && (k = await e.utxoUtils.buildBatchProcess(_, f, t)), console.log({ allUtxos: k }), await o(e, u);
51
68
  let A = await b(e, k, m);
52
- return { inputUtxos: l ? A.filter((e) => e.isBlocked) : A.filter((e) => !e.isBlocked) };
69
+ console.log("getInputUtxoAndBalance 8 inputUtxos", A);
70
+ let j = l ? A.filter((e) => e.isBlocked) : A.filter((e) => !e.isBlocked);
71
+ return console.log("getInputUtxoAndBalance 9 filteredInputUtxos", j), { inputUtxos: j };
53
72
  }, C = async ({ hinkal: e, chainId: n, passedShieldedPublicKey: a = void 0, ethAddress: o = void 0, resetCacheBefore: s = !1, allowRemoteDecryption: c = !1 }) => {
54
73
  let l = o ?? await e.getEthereumAddressByChain(n), u = r(t(n) ? p(l) : l), { inputUtxos: d } = await S({
55
74
  hinkal: e,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "h_test_1",
3
- "version": "0.0.42",
3
+ "version": "0.0.45",
4
4
  "homepage": "hinkal.io",
5
5
  "author": {
6
6
  "name": "Hinkal Protocol"