@gardenfi/core 0.2.0-beta.40 → 0.2.0-beta.41

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -20,7 +20,7 @@
20
20
  OP_CHECKSIGADD
21
21
  OP_2
22
22
  OP_NUMEQUAL
23
- `.trim().replace(/\s+/g," "))}leaves(){return[{version:tr,output:this.redeemLeaf()},[{version:tr,output:this.refundLeaf()},{version:tr,output:this.instantRefundLeaf()}]]}generateMerkleProofFor(t){const r=this.leafHash(1),n=this.leafHash(2),i=this.leafHash(0);switch(t){case 1:{const a=Ta(i,n);return[be.crypto.taggedHash("TapBranch",Buffer.concat(a))]}case 0:return[n,r];case 2:return[i,r];default:throw new Error(me.invalidLeaf)}}}function Lr(e,t){const r=[];for(let n=0;n<t;n++)r.push(e);return r}class $a{constructor(){this.cache={}}set(t,r,n,i){const a={txHash:n,timeStamp:Date.now(),btcRedeemUTXO:i};this.cache[`${r}_${t.create_order.create_id}`]=a}get(t,r){return this.cache[`${r}_${t.create_order.create_id}`]||null}remove(t,r){delete this.cache[`${r}_${t.create_order.create_id}`]}}class Ha{constructor(t){if(this.eventListeners=new Map,this.getOrderThreshold=20,this.pendingOrdersCount=0,this.useRelay=!0,this.orderBook=new J.Orderbook({url:t.orderbookURl,walletClient:t.wallets.evmWallet,auth:t.auth}),this.quote=t.quote,this.secretManager=t.secretManager,this.wallets=t.wallets,this.orderbookUrl=t.orderbookURl,this.auth=t.auth,this.orderExecutorCache=new $a,!t.wallets.evmWallet.account)throw new Error("Account not found in evmWallet");this.evmAddress=t.wallets.evmWallet.account.address}getPendingOrderCount(){return this.pendingOrdersCount}setUseRelay(t){this.useRelay=t}async swap(t){const r=await this.validateAndFillParams(t);if(r.error)return L.Err(r.error);const{sendAddress:n,receiveAddress:i,timelock:a}=r.val,u=await this.orderBook.getOrdersCount(this.evmAddress);if(u.error)return L.Err(u.error);const f=u.val+1,l=this.secretManager.generateSecret(f);if(l.error)return L.Err(l.error);const{strategyId:y,btcAddress:g}=t.additionalData,m={strategy_id:y,...g&&{bitcoin_optional_recipient:g}},B={source_chain:t.fromAsset.chain,destination_chain:t.toAsset.chain,source_asset:t.fromAsset.atomicSwapAddress,destination_asset:t.toAsset.atomicSwapAddress,initiator_source_address:n,initiator_destination_address:i,source_amount:t.sendAmount,destination_amount:t.receiveAmount,fee:"1",nonce:f.toString(),timelock:a,secret_hash:L.trim0x(l.val.secretHash),min_destination_confirmations:t.minDestinationConfirmations??0,additional_data:m},I=await this.quote.getAttestedQuote(B);if(I.error)return L.Err(I.error);const S=await this.orderBook.createOrder(I.val);if(S.error)return L.Err(S.error);const P=await this.pollOrder(S.val);return P.error?L.Err(P.error):L.Ok(P.val)}async validateAndFillParams(t){if(t.fromAsset.chain===t.toAsset.chain&&t.fromAsset.atomicSwapAddress===t.toAsset.atomicSwapAddress)return L.Err("Source and destination assets cannot be the same");if(J.isMainnet(t.fromAsset.chain)&&!J.isMainnet(t.toAsset.chain)||!J.isMainnet(t.fromAsset.chain)&&J.isMainnet(t.toAsset.chain))return L.Err("Both assets should be on the same network (either mainnet or testnet)");if(J.isBitcoin(t.fromAsset.chain)||J.isBitcoin(t.toAsset.chain)){if(!this.wallets.btcWallet)return L.Err("btcWallet is required for bitcoin chain. Please provide btcWallet in the constructor");if(!t.additionalData.btcAddress)return L.Err("btcAddress in additionalData is required for bitcoin chain")}const r=await this.getAddresses(t.fromAsset.chain);if(r.error)return L.Err(r.error);const n=await this.getAddresses(t.toAsset.chain);if(n.error)return L.Err(n.error);const i=this.validateAmount(t.sendAmount);if(i.error)return L.Err(i.error);const a=this.validateAmount(t.receiveAmount);if(a.error)return L.Err(a.error);if(i<a)return L.Err("Send amount should be greater than receive amount");const u=this.getTimelock(t.fromAsset.chain);return u?L.Ok({sendAddress:r.val,receiveAddress:n.val,timelock:t.timelock??u}):L.Err("Unsupported chain for timelock")}async getAddresses(t){var n;switch(J.getBlockchainType(t)){case J.BlockchainType.EVM:return this.wallets.evmWallet.account?L.Ok(this.wallets.evmWallet.account.address):L.Err("EVM Wallet not found");case J.BlockchainType.Bitcoin:{const i=await((n=this.wallets.btcWallet)==null?void 0:n.getPublicKey());return!i||!Pa(i)?L.Err("Invalid btc public key"):L.Ok(Ot(i))}default:return L.Err("Unsupported chain")}}validateAmount(t){if(t==null||t.includes("."))return L.Err("Invalid amount ",t);const r=new Ms(t);return!r.isInteger()||r.isNaN()||r.lt(0)||r.isLessThanOrEqualTo(0)?L.Err("Invalid amount ",t):L.Ok(r)}getTimelock(t){switch(J.getBlockchainType(t)){case J.BlockchainType.EVM:return Yr.evm;case J.BlockchainType.Bitcoin:return Yr.btc;default:return}}async pollOrder(t){let r=await this.orderBook.getOrder(t,!0),n=0;for(;n<this.getOrderThreshold;){if(await _e.sleep(1e3),n++,r.error){if(!r.error.includes("result is undefined"))return L.Err(r.error)}else if(r.val&&r.val.create_order.create_id.toLowerCase()===t.toLowerCase())return L.Ok(r.val);r=await this.orderBook.getOrder(t,!0)}return L.Err(`Order not found, createOrder id: ${t}`)}emit(t,...r){(this.eventListeners.get(t)??[]).forEach(i=>{i(...r)})}async execute(t=5e3){return await this.orderBook.subscribeToOrders(!0,t,async r=>{this.pendingOrdersCount=r.data.length,this.emit("onPendingOrdersChanged",r.data);for(let n=0;n<r.data.length;n++){const i=r.data[n],a=i.source_swap.chain,u=i.destination_swap.chain,f=this.getWallet(a),l=this.getWallet(u);if(f.error||l.error||!f.val||!l.val){this.emit("error",i,"Source or Destination Wallet not found while executing order");return}const y=await this.fetchCurrentBlockNumbers(i,{source:f.val,destination:l.val});if(y.error){this.emit("error",i,"Error while fetching CurrentBlockNumbers: "+y.error);return}switch(zi(i,y.val.source,y.val.destination)){case ye.Redeem:{const m=this.secretManager.generateSecret(Number(i.create_order.nonce));if(m.error){this.emit("error",i,m.error);return}switch(J.getBlockchainType(i.destination_swap.chain)){case J.BlockchainType.EVM:{await this.evmRedeem(i,m.val.secret);break}case J.BlockchainType.Bitcoin:{await this.btcRedeem(l.val,i,m.val.secret);break}default:this.emit("error",i,"Unsupported chain: "+i.destination_swap.chain)}break}case ye.Refund:{switch(J.getBlockchainType(i.source_swap.chain)){case J.BlockchainType.EVM:{this.emit("error",i,"EVM refund is automatically done by relay service");break}case J.BlockchainType.Bitcoin:{await this.btcRefund(f.val,i);break}default:this.emit("error",i,"Unsupported chain: "+i.source_swap.chain)}break}}}},{per_page:500},!0)}async evmRedeem(t,r){if(this.emit("log",t.create_order.create_id,"executing evm redeem"),this.orderExecutorCache.get(t,ye.Redeem)){this.emit("log",t.create_order.create_id,"already redeemed");return}const a=await new ji(t,this.orderbookUrl,this.auth).redeem(t.create_order.create_id,r);if(a.error){this.emit("error",t,a.error);return}this.emit("success",t,ye.Redeem,a.val),this.orderExecutorCache.set(t,ye.Redeem,a.val)}async btcRedeem(t,r,n){var u;const i=this.orderExecutorCache.get(r,ye.Redeem);let a=!1;if(i)if(i.btcRedeemUTXO&&i.btcRedeemUTXO!==r.destination_swap.initiate_tx_hash)a=!0,this.emit("log",r.create_order.create_id,"rbf btc redeem");else{this.emit("log",r.create_order.create_id,"btcRedeem: already redeemed");return}this.emit("log",r.create_order.create_id,"executing btc redeem");try{const l=await(await ur.from(t,Number(r.destination_swap.amount),r.create_order.secret_hash,Ot(r.destination_swap.initiator),Ot(r.destination_swap.redeemer),r.destination_swap.timelock,a?[r.destination_swap.initiate_tx_hash]:[])).redeem(L.trim0x(n),(u=r.create_order.additional_data)==null?void 0:u.bitcoin_optional_recipient);this.emit("success",r,ye.Redeem,l),this.orderExecutorCache.set(r,ye.Redeem,l,r.destination_swap.initiate_tx_hash)}catch(f){this.emit("error",r,"Failed btc redeem: "+f)}}async btcRefund(t,r){var n;if(!this.orderExecutorCache.get(r,ye.Refund)){this.emit("log",r.create_order.create_id,"executing btc refund");try{const a=await(await ur.from(t,Number(r.source_swap.amount),r.create_order.secret_hash,Ot(r.source_swap.initiator),Ot(r.source_swap.redeemer),r.source_swap.timelock)).refund((n=r.create_order.additional_data)==null?void 0:n.bitcoin_optional_recipient);this.emit("success",r,ye.Refund,a),this.orderExecutorCache.set(r,ye.Refund,a)}catch(i){this.emit("error",r,"Failed btc refund: "+i)}}}getWallet(t){switch(J.getBlockchainType(t)){case J.BlockchainType.EVM:return L.Ok(this.wallets.evmWallet);case J.BlockchainType.Bitcoin:return L.Ok(this.wallets.btcWallet);default:return L.Err("Unsupported chain for wallet")}}on(t,r){const n=this.eventListeners.get(t)??[];n.push(r),this.eventListeners.set(t,n)}off(t,r){const n=this.eventListeners.get(t)??[],i=n.indexOf(r);i!==-1&&n.splice(i,1)}async fetchCurrentBlockNumbers(t,r){if(!r||!r.source||!r.destination)return L.Err("Provide wallets to fetch the current block number");const n=J.isBitcoin(t.source_swap.chain)?await _e.fetchBitcoinBlockNumber(await r.source.getProvider()):await _e.fetchEVMBlockNumber(r.source);if(n.error)return L.Err(n.error);const i=J.isBitcoin(t.destination_swap.chain)?await _e.fetchBitcoinBlockNumber(await r.destination.getProvider()):await _e.fetchEVMBlockNumber(r.destination);return i.error?L.Err(i.error):L.Ok({source:n.val,destination:i.val})}}var Qe=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function za(e){if(e.__esModule)return e;var t=e.default;if(typeof t=="function"){var r=function n(){return this instanceof n?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};r.prototype=t.prototype}else r={};return Object.defineProperty(r,"__esModule",{value:!0}),Object.keys(e).forEach(function(n){var i=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(r,n,i.get?i:{enumerable:!0,get:function(){return e[n]}})}),r}var Gi={},vt={},Et={};Object.defineProperty(Et,"__esModule",{value:!0});Et.testnet=Et.bitcoin=void 0;Et.bitcoin={messagePrefix:`Bitcoin Signed Message:
23
+ `.trim().replace(/\s+/g," "))}leaves(){return[{version:tr,output:this.redeemLeaf()},[{version:tr,output:this.refundLeaf()},{version:tr,output:this.instantRefundLeaf()}]]}generateMerkleProofFor(t){const r=this.leafHash(1),n=this.leafHash(2),i=this.leafHash(0);switch(t){case 1:{const a=Ta(i,n);return[be.crypto.taggedHash("TapBranch",Buffer.concat(a))]}case 0:return[n,r];case 2:return[i,r];default:throw new Error(me.invalidLeaf)}}}function Lr(e,t){const r=[];for(let n=0;n<t;n++)r.push(e);return r}class $a{constructor(){this.cache={}}set(t,r,n,i){const a={txHash:n,timeStamp:Date.now(),btcRedeemUTXO:i};this.cache[`${r}_${t.create_order.create_id}`]=a}get(t,r){return this.cache[`${r}_${t.create_order.create_id}`]||null}remove(t,r){delete this.cache[`${r}_${t.create_order.create_id}`]}}class Ha{constructor(t){if(this.eventListeners=new Map,this.getOrderThreshold=20,this.pendingOrdersCount=0,this.useRelay=!0,this.orderBook=new J.Orderbook({url:t.orderbookURl,walletClient:t.wallets.evmWallet,auth:t.auth}),this.quote=t.quote,this.secretManager=t.secretManager,this.wallets=t.wallets,this.orderbookUrl=t.orderbookURl,this.auth=t.auth,this.orderExecutorCache=new $a,!t.wallets.evmWallet.account)throw new Error("Account not found in evmWallet");this.evmAddress=t.wallets.evmWallet.account.address}getPendingOrderCount(){return this.pendingOrdersCount}setUseRelay(t){this.useRelay=t}async swap(t){const r=await this.validateAndFillParams(t);if(r.error)return L.Err(r.error);const{sendAddress:n,receiveAddress:i,timelock:a}=r.val,u=await this.orderBook.getOrdersCount(this.evmAddress);if(u.error)return L.Err(u.error);const f=u.val+1,l=this.secretManager.generateSecret(f);if(l.error)return L.Err(l.error);const{strategyId:y,btcAddress:g}=t.additionalData,m={strategy_id:y,...g&&{bitcoin_optional_recipient:g}},B={source_chain:t.fromAsset.chain,destination_chain:t.toAsset.chain,source_asset:t.fromAsset.atomicSwapAddress,destination_asset:t.toAsset.atomicSwapAddress,initiator_source_address:n,initiator_destination_address:i,source_amount:t.sendAmount,destination_amount:t.receiveAmount,fee:"1",nonce:f.toString(),timelock:a,secret_hash:L.trim0x(l.val.secretHash),min_destination_confirmations:t.minDestinationConfirmations??0,additional_data:m},I=await this.quote.getAttestedQuote(B);if(I.error)return L.Err(I.error);const S=await this.orderBook.createOrder(I.val);if(S.error)return L.Err(S.error);const P=await this.pollOrder(S.val);return P.error?L.Err(P.error):L.Ok(P.val)}async validateAndFillParams(t){if(t.fromAsset.chain===t.toAsset.chain&&t.fromAsset.atomicSwapAddress===t.toAsset.atomicSwapAddress)return L.Err("Source and destination assets cannot be the same");if(J.isMainnet(t.fromAsset.chain)&&!J.isMainnet(t.toAsset.chain)||!J.isMainnet(t.fromAsset.chain)&&J.isMainnet(t.toAsset.chain))return L.Err("Both assets should be on the same network (either mainnet or testnet)");if(J.isBitcoin(t.fromAsset.chain)||J.isBitcoin(t.toAsset.chain)){if(!this.wallets.btcWallet)return L.Err("btcWallet is required for bitcoin chain. Please provide btcWallet in the constructor");if(!t.additionalData.btcAddress)return L.Err("btcAddress in additionalData is required for bitcoin chain")}const r=await this.getAddresses(t.fromAsset.chain);if(r.error)return L.Err(r.error);const n=await this.getAddresses(t.toAsset.chain);if(n.error)return L.Err(n.error);const i=this.validateAmount(t.sendAmount);if(i.error)return L.Err(i.error);const a=this.validateAmount(t.receiveAmount);if(a.error)return L.Err(a.error);if(i<a)return L.Err("Send amount should be greater than receive amount");const u=this.getTimelock(t.fromAsset.chain);return u?L.Ok({sendAddress:r.val,receiveAddress:n.val,timelock:t.timelock??u}):L.Err("Unsupported chain for timelock")}async getAddresses(t){var n;switch(J.getBlockchainType(t)){case J.BlockchainType.EVM:return this.wallets.evmWallet.account?L.Ok(this.wallets.evmWallet.account.address):L.Err("EVM Wallet not found");case J.BlockchainType.Bitcoin:{const i=await((n=this.wallets.btcWallet)==null?void 0:n.getPublicKey());return!i||!Pa(i)?L.Err("Invalid btc public key"):L.Ok(Ot(i))}default:return L.Err("Unsupported chain")}}validateAmount(t){if(t==null||t.includes("."))return L.Err("Invalid amount ",t);const r=new Ms(t);return!r.isInteger()||r.isNaN()||r.lt(0)||r.isLessThanOrEqualTo(0)?L.Err("Invalid amount ",t):L.Ok(r)}getTimelock(t){switch(J.getBlockchainType(t)){case J.BlockchainType.EVM:return Yr.evm;case J.BlockchainType.Bitcoin:return Yr.btc;default:return}}async pollOrder(t){let r=await this.orderBook.getOrder(t,!0),n=0;for(;n<this.getOrderThreshold;){if(await _e.sleep(1e3),n++,r.error){if(!r.error.includes("result is undefined"))return L.Err(r.error)}else if(r.val&&r.val.create_order.create_id.toLowerCase()===t.toLowerCase())return L.Ok(r.val);r=await this.orderBook.getOrder(t,!0)}return L.Err(`Order not found, createOrder id: ${t}`)}emit(t,...r){(this.eventListeners.get(t)??[]).forEach(i=>{i(...r)})}async execute(t=5e3){return await this.orderBook.subscribeToOrders(!0,t,async r=>{this.pendingOrdersCount=r.data.length,this.emit("onPendingOrdersChanged",r.data);for(let n=0;n<r.data.length;n++){const i=r.data[n],a=i.source_swap.chain,u=i.destination_swap.chain,f=this.getWallet(a),l=this.getWallet(u);if(f.error||l.error||!f.val||!l.val){this.emit("error",i,"Source or Destination Wallet not found while executing order");return}const y=await this.fetchCurrentBlockNumbers(i,{source:f.val,destination:l.val});if(y.error){this.emit("error",i,"Error while fetching CurrentBlockNumbers: "+y.error);return}const g=zi(i,y.val.source,y.val.destination);switch(console.log("orderAction :",g),this.emit("log",i.create_order.create_id,g),g){case ye.Redeem:{const m=this.secretManager.generateSecret(Number(i.create_order.nonce));if(m.error){this.emit("error",i,m.error);return}switch(J.getBlockchainType(i.destination_swap.chain)){case J.BlockchainType.EVM:{await this.evmRedeem(i,m.val.secret);break}case J.BlockchainType.Bitcoin:{await this.btcRedeem(l.val,i,m.val.secret);break}default:this.emit("error",i,"Unsupported chain: "+i.destination_swap.chain)}break}case ye.Refund:{switch(J.getBlockchainType(i.source_swap.chain)){case J.BlockchainType.EVM:{this.emit("error",i,"EVM refund is automatically done by relay service");break}case J.BlockchainType.Bitcoin:{await this.btcRefund(f.val,i);break}default:this.emit("error",i,"Unsupported chain: "+i.source_swap.chain)}break}}}},{per_page:500},!0)}async evmRedeem(t,r){if(this.emit("log",t.create_order.create_id,"executing evm redeem"),this.orderExecutorCache.get(t,ye.Redeem)){this.emit("log",t.create_order.create_id,"already redeemed");return}const a=await new ji(t,this.orderbookUrl,this.auth).redeem(t.create_order.create_id,r);if(a.error){this.emit("error",t,a.error);return}this.emit("success",t,ye.Redeem,a.val),this.orderExecutorCache.set(t,ye.Redeem,a.val)}async btcRedeem(t,r,n){var u;const i=this.orderExecutorCache.get(r,ye.Redeem);let a=!1;if(i)if(i.btcRedeemUTXO&&i.btcRedeemUTXO!==r.destination_swap.initiate_tx_hash)a=!0,this.emit("log",r.create_order.create_id,"rbf btc redeem");else{this.emit("log",r.create_order.create_id,"btcRedeem: already redeemed");return}this.emit("log",r.create_order.create_id,"executing btc redeem");try{const l=await(await ur.from(t,Number(r.destination_swap.amount),r.create_order.secret_hash,Ot(r.destination_swap.initiator),Ot(r.destination_swap.redeemer),r.destination_swap.timelock,a?[r.destination_swap.initiate_tx_hash]:[])).redeem(L.trim0x(n),(u=r.create_order.additional_data)==null?void 0:u.bitcoin_optional_recipient);this.emit("success",r,ye.Redeem,l),this.orderExecutorCache.set(r,ye.Redeem,l,r.destination_swap.initiate_tx_hash)}catch(f){this.emit("error",r,"Failed btc redeem: "+f)}}async btcRefund(t,r){var n;if(!this.orderExecutorCache.get(r,ye.Refund)){this.emit("log",r.create_order.create_id,"executing btc refund");try{const a=await(await ur.from(t,Number(r.source_swap.amount),r.create_order.secret_hash,Ot(r.source_swap.initiator),Ot(r.source_swap.redeemer),r.source_swap.timelock)).refund((n=r.create_order.additional_data)==null?void 0:n.bitcoin_optional_recipient);this.emit("success",r,ye.Refund,a),this.orderExecutorCache.set(r,ye.Refund,a)}catch(i){this.emit("error",r,"Failed btc refund: "+i)}}}getWallet(t){switch(J.getBlockchainType(t)){case J.BlockchainType.EVM:return L.Ok(this.wallets.evmWallet);case J.BlockchainType.Bitcoin:return L.Ok(this.wallets.btcWallet);default:return L.Err("Unsupported chain for wallet")}}on(t,r){const n=this.eventListeners.get(t)??[];n.push(r),this.eventListeners.set(t,n)}off(t,r){const n=this.eventListeners.get(t)??[],i=n.indexOf(r);i!==-1&&n.splice(i,1)}async fetchCurrentBlockNumbers(t,r){if(!r||!r.source||!r.destination)return L.Err("Provide wallets to fetch the current block number");const n=J.isBitcoin(t.source_swap.chain)?await _e.fetchBitcoinBlockNumber(await r.source.getProvider()):await _e.fetchEVMBlockNumber(r.source);if(n.error)return L.Err(n.error);const i=J.isBitcoin(t.destination_swap.chain)?await _e.fetchBitcoinBlockNumber(await r.destination.getProvider()):await _e.fetchEVMBlockNumber(r.destination);return i.error?L.Err(i.error):L.Ok({source:n.val,destination:i.val})}}var Qe=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function za(e){if(e.__esModule)return e;var t=e.default;if(typeof t=="function"){var r=function n(){return this instanceof n?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};r.prototype=t.prototype}else r={};return Object.defineProperty(r,"__esModule",{value:!0}),Object.keys(e).forEach(function(n){var i=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(r,n,i.get?i:{enumerable:!0,get:function(){return e[n]}})}),r}var Gi={},vt={},Et={};Object.defineProperty(Et,"__esModule",{value:!0});Et.testnet=Et.bitcoin=void 0;Et.bitcoin={messagePrefix:`Bitcoin Signed Message:
24
24
  `,bech32:"bc",bip32:{public:76067358,private:76066276},pubKeyHash:0,scriptHash:5,wif:128};Et.testnet={messagePrefix:`Bitcoin Signed Message:
25
25
  `,bech32:"tb",bip32:{public:70617039,private:70615956},pubKeyHash:111,scriptHash:196,wif:239};var qi={},zt={Array:function(e){return e!=null&&e.constructor===Array},Boolean:function(e){return typeof e=="boolean"},Function:function(e){return typeof e=="function"},Nil:function(e){return e==null},Number:function(e){return typeof e=="number"},Object:function(e){return typeof e=="object"},String:function(e){return typeof e=="string"},"":function(){return!0}};zt.Null=zt.Nil;for(var Dn in zt)zt[Dn].toJSON=(function(e){return e}).bind(null,Dn);var yn=zt,it=yn;function Wi(e){return e.name||e.toString().match(/function (.*?)\s*\(/)[1]}function gn(e){return it.Nil(e)?"":Wi(e.constructor)}function ja(e){return it.Function(e)?"":it.String(e)?JSON.stringify(e):e&&it.Object(e)?"":e}function mn(e,t){Error.captureStackTrace&&Error.captureStackTrace(e,t)}function cr(e){return it.Function(e)?e.toJSON?e.toJSON():Wi(e):it.Array(e)?"Array":e&&it.Object(e)?"Object":e!==void 0?e:""}function Vi(e,t,r){var n=ja(t);return"Expected "+cr(e)+", got"+(r!==""?" "+r:"")+(n!==""?" "+n:"")}function ze(e,t,r){r=r||gn(t),this.message=Vi(e,t,r),mn(this,ze),this.__type=e,this.__value=t,this.__valueTypeName=r}ze.prototype=Object.create(Error.prototype);ze.prototype.constructor=ze;function Ga(e,t,r,n,i){var a='" of type ';return t==="key"&&(a='" with key type '),Vi('property "'+cr(r)+a+cr(e),n,i)}function mt(e,t,r,n,i){e?(i=i||gn(n),this.message=Ga(e,r,t,n,i)):this.message='Unexpected property "'+t+'"',mn(this,ze),this.__label=r,this.__property=t,this.__type=e,this.__value=n,this.__valueTypeName=i}mt.prototype=Object.create(Error.prototype);mt.prototype.constructor=ze;function qa(e,t){return new ze(e,{},t)}function Wa(e,t,r){return e instanceof mt?(t=t+"."+e.__property,e=new mt(e.__type,t,e.__label,e.__value,e.__valueTypeName)):e instanceof ze&&(e=new mt(e.__type,t,r,e.__value,e.__valueTypeName)),mn(e),e}var Ki={TfTypeError:ze,TfPropertyTypeError:mt,tfCustomError:qa,tfSubError:Wa,tfJSON:cr,getValueTypeName:gn},Or,$n;function Va(){if($n)return Or;$n=1;var e=yn,t=Ki;function r(E){return Buffer.isBuffer(E)}function n(E){return typeof E=="string"&&/^([0-9a-f]{2})+$/i.test(E)}function i(E,z){var N=E.toJSON();function $(se){if(!E(se))return!1;if(se.length===z)return!0;throw t.tfCustomError(N+"(Length: "+z+")",N+"(Length: "+se.length+")")}return $.toJSON=function(){return N},$}var a=i.bind(null,e.Array),u=i.bind(null,r),f=i.bind(null,n),l=i.bind(null,e.String);function y(E,z,N){N=N||e.Number;function $(se,Pe){return N(se,Pe)&&se>E&&se<z}return $.toJSON=function(){return`${N.toJSON()} between [${E}, ${z}]`},$}var g=Math.pow(2,53)-1;function m(E){return typeof E=="number"&&isFinite(E)}function B(E){return E<<24>>24===E}function I(E){return E<<16>>16===E}function S(E){return(E|0)===E}function P(E){return typeof E=="number"&&E>=-g&&E<=g&&Math.floor(E)===E}function T(E){return(E&255)===E}function k(E){return(E&65535)===E}function F(E){return E>>>0===E}function O(E){return typeof E=="number"&&E>=0&&E<=g&&Math.floor(E)===E}var C={ArrayN:a,Buffer:r,BufferN:u,Finite:m,Hex:n,HexN:f,Int8:B,Int16:I,Int32:S,Int53:P,Range:y,StringN:l,UInt8:T,UInt16:k,UInt32:F,UInt53:O};for(var U in C)C[U].toJSON=(function(E){return E}).bind(null,U);return Or=C,Or}var Kt=Ki,ce=yn,De=Kt.tfJSON,Yi=Kt.TfTypeError,Ji=Kt.TfPropertyTypeError,Ft=Kt.tfSubError,Ka=Kt.getValueTypeName,$e={arrayOf:function(t,r){t=Fe(t),r=r||{};function n(i,a){return!ce.Array(i)||ce.Nil(i)||r.minLength!==void 0&&i.length<r.minLength||r.maxLength!==void 0&&i.length>r.maxLength||r.length!==void 0&&i.length!==r.length?!1:i.every(function(u,f){try{return xe(t,u,a)}catch(l){throw Ft(l,f)}})}return n.toJSON=function(){var i="["+De(t)+"]";return r.length!==void 0?i+="{"+r.length+"}":(r.minLength!==void 0||r.maxLength!==void 0)&&(i+="{"+(r.minLength===void 0?0:r.minLength)+","+(r.maxLength===void 0?1/0:r.maxLength)+"}"),i},n},maybe:function e(t){t=Fe(t);function r(n,i){return ce.Nil(n)||t(n,i,e)}return r.toJSON=function(){return"?"+De(t)},r},map:function(t,r){t=Fe(t),r&&(r=Fe(r));function n(i,a){if(!ce.Object(i)||ce.Nil(i))return!1;for(var u in i){try{r&&xe(r,u,a)}catch(l){throw Ft(l,u,"key")}try{var f=i[u];xe(t,f,a)}catch(l){throw Ft(l,u)}}return!0}return r?n.toJSON=function(){return"{"+De(r)+": "+De(t)+"}"}:n.toJSON=function(){return"{"+De(t)+"}"},n},object:function(t){var r={};for(var n in t)r[n]=Fe(t[n]);function i(a,u){if(!ce.Object(a)||ce.Nil(a))return!1;var f;try{for(f in r){var l=r[f],y=a[f];xe(l,y,u)}}catch(g){throw Ft(g,f)}if(u){for(f in a)if(!r[f])throw new Ji(void 0,f)}return!0}return i.toJSON=function(){return De(r)},i},anyOf:function(){var t=[].slice.call(arguments).map(Fe);function r(n,i){return t.some(function(a){try{return xe(a,n,i)}catch{return!1}})}return r.toJSON=function(){return t.map(De).join("|")},r},allOf:function(){var t=[].slice.call(arguments).map(Fe);function r(n,i){return t.every(function(a){try{return xe(a,n,i)}catch{return!1}})}return r.toJSON=function(){return t.map(De).join(" & ")},r},quacksLike:function(t){function r(n){return t===Ka(n)}return r.toJSON=function(){return t},r},tuple:function(){var t=[].slice.call(arguments).map(Fe);function r(n,i){return ce.Nil(n)||ce.Nil(n.length)||i&&n.length!==t.length?!1:t.every(function(a,u){try{return xe(a,n[u],i)}catch(f){throw Ft(f,u)}})}return r.toJSON=function(){return"("+t.map(De).join(", ")+")"},r},value:function(t){function r(n){return n===t}return r.toJSON=function(){return t},r}};$e.oneOf=$e.anyOf;function Fe(e){if(ce.String(e))return e[0]==="?"?$e.maybe(e.slice(1)):ce[e]||$e.quacksLike(e);if(e&&ce.Object(e)){if(ce.Array(e)){if(e.length!==1)throw new TypeError("Expected compile() parameter of type Array of length 1");return $e.arrayOf(e[0])}return $e.object(e)}else if(ce.Function(e))return e;return $e.value(e)}function xe(e,t,r,n){if(ce.Function(e)){if(e(t,r))return!0;throw new Yi(n||e,t)}return xe(Fe(e),t,r)}for(var Xe in ce)xe[Xe]=ce[Xe];for(Xe in $e)xe[Xe]=$e[Xe];var Hn=Va();for(Xe in Hn)xe[Xe]=Hn[Xe];xe.compile=Fe;xe.TfTypeError=Yi;xe.TfPropertyTypeError=Ji;var Ya=xe;(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.maybe=e.Boolean=e.Array=e.Buffer256bit=e.Network=e.typeforce=void 0,e.typeforce=Ya,e.Network=e.typeforce.compile({messagePrefix:e.typeforce.oneOf(e.typeforce.Buffer,e.typeforce.String),bip32:{public:e.typeforce.UInt32,private:e.typeforce.UInt32},pubKeyHash:e.typeforce.UInt8,scriptHash:e.typeforce.UInt8,wif:e.typeforce.UInt8}),e.Buffer256bit=e.typeforce.BufferN(32),e.Array=e.typeforce.Array,e.Boolean=e.typeforce.Boolean,e.maybe=e.typeforce.maybe})(qi);var Qr={exports:{}},Zr={exports:{}},At={},mr={};mr.byteLength=Qa;mr.toByteArray=ef;mr.fromByteArray=nf;var Ue=[],Re=[],Ja=typeof Uint8Array<"u"?Uint8Array:Array,Fr="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(var yt=0,Xa=Fr.length;yt<Xa;++yt)Ue[yt]=Fr[yt],Re[Fr.charCodeAt(yt)]=yt;Re[45]=62;Re[95]=63;function Xi(e){var t=e.length;if(t%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var r=e.indexOf("=");r===-1&&(r=t);var n=r===t?0:4-r%4;return[r,n]}function Qa(e){var t=Xi(e),r=t[0],n=t[1];return(r+n)*3/4-n}function Za(e,t,r){return(t+r)*3/4-r}function ef(e){var t,r=Xi(e),n=r[0],i=r[1],a=new Ja(Za(e,n,i)),u=0,f=i>0?n-4:n,l;for(l=0;l<f;l+=4)t=Re[e.charCodeAt(l)]<<18|Re[e.charCodeAt(l+1)]<<12|Re[e.charCodeAt(l+2)]<<6|Re[e.charCodeAt(l+3)],a[u++]=t>>16&255,a[u++]=t>>8&255,a[u++]=t&255;return i===2&&(t=Re[e.charCodeAt(l)]<<2|Re[e.charCodeAt(l+1)]>>4,a[u++]=t&255),i===1&&(t=Re[e.charCodeAt(l)]<<10|Re[e.charCodeAt(l+1)]<<4|Re[e.charCodeAt(l+2)]>>2,a[u++]=t>>8&255,a[u++]=t&255),a}function tf(e){return Ue[e>>18&63]+Ue[e>>12&63]+Ue[e>>6&63]+Ue[e&63]}function rf(e,t,r){for(var n,i=[],a=t;a<r;a+=3)n=(e[a]<<16&16711680)+(e[a+1]<<8&65280)+(e[a+2]&255),i.push(tf(n));return i.join("")}function nf(e){for(var t,r=e.length,n=r%3,i=[],a=16383,u=0,f=r-n;u<f;u+=a)i.push(rf(e,u,u+a>f?f:u+a));return n===1?(t=e[r-1],i.push(Ue[t>>2]+Ue[t<<4&63]+"==")):n===2&&(t=(e[r-2]<<8)+e[r-1],i.push(Ue[t>>10]+Ue[t>>4&63]+Ue[t<<2&63]+"=")),i.join("")}var wn={};/*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */wn.read=function(e,t,r,n,i){var a,u,f=i*8-n-1,l=(1<<f)-1,y=l>>1,g=-7,m=r?i-1:0,B=r?-1:1,I=e[t+m];for(m+=B,a=I&(1<<-g)-1,I>>=-g,g+=f;g>0;a=a*256+e[t+m],m+=B,g-=8);for(u=a&(1<<-g)-1,a>>=-g,g+=n;g>0;u=u*256+e[t+m],m+=B,g-=8);if(a===0)a=1-y;else{if(a===l)return u?NaN:(I?-1:1)*(1/0);u=u+Math.pow(2,n),a=a-y}return(I?-1:1)*u*Math.pow(2,a-n)};wn.write=function(e,t,r,n,i,a){var u,f,l,y=a*8-i-1,g=(1<<y)-1,m=g>>1,B=i===23?Math.pow(2,-24)-Math.pow(2,-77):0,I=n?0:a-1,S=n?1:-1,P=t<0||t===0&&1/t<0?1:0;for(t=Math.abs(t),isNaN(t)||t===1/0?(f=isNaN(t)?1:0,u=g):(u=Math.floor(Math.log(t)/Math.LN2),t*(l=Math.pow(2,-u))<1&&(u--,l*=2),u+m>=1?t+=B/l:t+=B*Math.pow(2,1-m),t*l>=2&&(u++,l/=2),u+m>=g?(f=0,u=g):u+m>=1?(f=(t*l-1)*Math.pow(2,i),u=u+m):(f=t*Math.pow(2,m-1)*Math.pow(2,i),u=0));i>=8;e[r+I]=f&255,I+=S,f/=256,i-=8);for(u=u<<i|f,y+=i;y>0;e[r+I]=u&255,I+=S,u/=256,y-=8);e[r+I-S]|=P*128};/*!
26
26
  * The buffer module from node.js, for the browser.
package/dist/index.js CHANGED
@@ -2853,11 +2853,12 @@ class u0 {
2853
2853
  );
2854
2854
  return;
2855
2855
  }
2856
- switch (qa(
2856
+ const g = qa(
2857
2857
  i,
2858
2858
  y.val.source,
2859
2859
  y.val.destination
2860
- )) {
2860
+ );
2861
+ switch (console.log("orderAction :", g), this.emit("log", i.create_order.create_id, g), g) {
2861
2862
  case ye.Redeem: {
2862
2863
  const m = this.secretManager.generateSecret(
2863
2864
  Number(i.create_order.nonce)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gardenfi/core",
3
- "version": "0.2.0-beta.40",
3
+ "version": "0.2.0-beta.41",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist"