@gardenfi/core 0.2.0-beta.75 → 0.2.0-beta.76
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 +31 -1
- package/dist/index.js +7813 -28
- package/package.json +1 -1
- package/dist/index10.cjs +0 -1
- package/dist/index10.js +0 -112
- package/dist/index100.cjs +0 -1
- package/dist/index100.js +0 -23
- package/dist/index101.cjs +0 -1
- package/dist/index101.js +0 -9
- package/dist/index102.cjs +0 -1
- package/dist/index102.js +0 -35
- package/dist/index103.cjs +0 -1
- package/dist/index103.js +0 -4
- package/dist/index104.cjs +0 -1
- package/dist/index104.js +0 -40
- package/dist/index105.cjs +0 -1
- package/dist/index105.js +0 -31
- package/dist/index106.cjs +0 -1
- package/dist/index106.js +0 -9
- package/dist/index107.cjs +0 -1
- package/dist/index107.js +0 -7
- package/dist/index108.cjs +0 -1
- package/dist/index108.js +0 -13
- package/dist/index109.cjs +0 -1
- package/dist/index109.js +0 -4
- package/dist/index11.cjs +0 -20
- package/dist/index11.js +0 -380
- package/dist/index110.cjs +0 -1
- package/dist/index110.js +0 -60
- package/dist/index111.cjs +0 -1
- package/dist/index111.js +0 -4
- package/dist/index112.cjs +0 -1
- package/dist/index112.js +0 -42
- package/dist/index113.cjs +0 -1
- package/dist/index113.js +0 -45
- package/dist/index114.cjs +0 -1
- package/dist/index114.js +0 -20
- package/dist/index115.cjs +0 -1
- package/dist/index115.js +0 -111
- package/dist/index116.cjs +0 -1
- package/dist/index116.js +0 -23
- package/dist/index117.cjs +0 -1
- package/dist/index117.js +0 -228
- package/dist/index118.cjs +0 -1
- package/dist/index118.js +0 -6
- package/dist/index119.cjs +0 -1
- package/dist/index119.js +0 -160
- package/dist/index12.cjs +0 -1
- package/dist/index12.js +0 -22
- package/dist/index120.cjs +0 -1
- package/dist/index120.js +0 -4
- package/dist/index121.cjs +0 -1
- package/dist/index121.js +0 -75
- package/dist/index122.cjs +0 -1
- package/dist/index122.js +0 -64
- package/dist/index123.cjs +0 -1
- package/dist/index123.js +0 -37
- package/dist/index124.cjs +0 -1
- package/dist/index124.js +0 -7
- package/dist/index125.cjs +0 -1
- package/dist/index125.js +0 -107
- package/dist/index126.cjs +0 -1
- package/dist/index126.js +0 -15
- package/dist/index127.cjs +0 -1
- package/dist/index127.js +0 -35
- package/dist/index128.cjs +0 -1
- package/dist/index128.js +0 -4
- package/dist/index129.cjs +0 -1
- package/dist/index129.js +0 -32
- package/dist/index13.cjs +0 -1
- package/dist/index13.js +0 -396
- package/dist/index130.cjs +0 -1
- package/dist/index130.js +0 -4
- package/dist/index131.cjs +0 -1
- package/dist/index131.js +0 -358
- package/dist/index132.cjs +0 -1
- package/dist/index132.js +0 -241
- package/dist/index133.cjs +0 -1
- package/dist/index133.js +0 -70
- package/dist/index134.cjs +0 -1
- package/dist/index134.js +0 -64
- package/dist/index135.cjs +0 -1
- package/dist/index135.js +0 -14
- package/dist/index136.cjs +0 -1
- package/dist/index136.js +0 -47
- package/dist/index137.cjs +0 -1
- package/dist/index137.js +0 -65
- package/dist/index138.cjs +0 -1
- package/dist/index138.js +0 -21
- package/dist/index139.cjs +0 -1
- package/dist/index139.js +0 -228
- package/dist/index14.cjs +0 -1
- package/dist/index14.js +0 -28
- package/dist/index140.cjs +0 -1
- package/dist/index140.js +0 -5
- package/dist/index141.cjs +0 -1
- package/dist/index141.js +0 -171
- package/dist/index142.cjs +0 -1
- package/dist/index142.js +0 -30
- package/dist/index143.cjs +0 -1
- package/dist/index143.js +0 -23
- package/dist/index144.cjs +0 -1
- package/dist/index144.js +0 -72
- package/dist/index145.cjs +0 -1
- package/dist/index145.js +0 -130
- package/dist/index146.cjs +0 -1
- package/dist/index146.js +0 -9
- package/dist/index147.cjs +0 -1
- package/dist/index147.js +0 -4
- package/dist/index148.cjs +0 -1
- package/dist/index148.js +0 -28
- package/dist/index149.cjs +0 -1
- package/dist/index149.js +0 -4
- package/dist/index15.cjs +0 -1
- package/dist/index15.js +0 -34
- package/dist/index16.cjs +0 -1
- package/dist/index16.js +0 -27
- package/dist/index17.cjs +0 -1
- package/dist/index17.js +0 -33
- package/dist/index18.cjs +0 -1
- package/dist/index18.js +0 -32
- package/dist/index19.cjs +0 -1
- package/dist/index19.js +0 -55
- package/dist/index2.cjs +0 -1
- package/dist/index2.js +0 -412
- package/dist/index20.cjs +0 -1
- package/dist/index20.js +0 -28
- package/dist/index21.cjs +0 -1
- package/dist/index21.js +0 -4
- package/dist/index22.cjs +0 -1
- package/dist/index22.js +0 -140
- package/dist/index23.cjs +0 -1
- package/dist/index23.js +0 -4
- package/dist/index24.cjs +0 -1
- package/dist/index24.js +0 -11
- package/dist/index25.cjs +0 -1
- package/dist/index25.js +0 -11
- package/dist/index26.cjs +0 -3
- package/dist/index26.js +0 -30
- package/dist/index27.cjs +0 -1
- package/dist/index27.js +0 -17
- package/dist/index28.cjs +0 -2
- package/dist/index28.js +0 -27
- package/dist/index29.cjs +0 -1
- package/dist/index29.js +0 -43
- package/dist/index3.cjs +0 -1
- package/dist/index3.js +0 -5
- package/dist/index30.cjs +0 -1
- package/dist/index30.js +0 -201
- package/dist/index31.cjs +0 -1
- package/dist/index31.js +0 -4
- package/dist/index32.cjs +0 -1
- package/dist/index32.js +0 -4
- package/dist/index33.cjs +0 -1
- package/dist/index33.js +0 -4
- package/dist/index34.cjs +0 -1
- package/dist/index34.js +0 -15
- package/dist/index35.cjs +0 -1
- package/dist/index35.js +0 -39
- package/dist/index36.cjs +0 -1
- package/dist/index36.js +0 -44
- package/dist/index37.cjs +0 -1
- package/dist/index37.js +0 -30
- package/dist/index38.cjs +0 -1
- package/dist/index38.js +0 -17
- package/dist/index39.cjs +0 -1
- package/dist/index39.js +0 -26
- package/dist/index4.cjs +0 -1
- package/dist/index4.js +0 -18
- package/dist/index40.cjs +0 -1
- package/dist/index40.js +0 -28
- package/dist/index41.cjs +0 -1
- package/dist/index41.js +0 -57
- package/dist/index42.cjs +0 -1
- package/dist/index42.js +0 -30
- package/dist/index43.cjs +0 -1
- package/dist/index43.js +0 -177
- package/dist/index44.cjs +0 -1
- package/dist/index44.js +0 -4
- package/dist/index45.cjs +0 -1
- package/dist/index45.js +0 -37
- package/dist/index46.cjs +0 -1
- package/dist/index46.js +0 -11
- package/dist/index47.cjs +0 -1
- package/dist/index47.js +0 -15
- package/dist/index48.cjs +0 -1
- package/dist/index48.js +0 -14
- package/dist/index49.cjs +0 -1
- package/dist/index49.js +0 -6
- package/dist/index5.cjs +0 -1
- package/dist/index5.js +0 -99
- package/dist/index50.cjs +0 -1
- package/dist/index50.js +0 -48
- package/dist/index51.cjs +0 -1
- package/dist/index51.js +0 -45
- package/dist/index52.cjs +0 -1
- package/dist/index52.js +0 -174
- package/dist/index53.cjs +0 -1
- package/dist/index53.js +0 -15
- package/dist/index54.cjs +0 -1
- package/dist/index54.js +0 -7
- package/dist/index55.cjs +0 -1
- package/dist/index55.js +0 -19
- package/dist/index56.cjs +0 -1
- package/dist/index56.js +0 -14
- package/dist/index57.cjs +0 -1
- package/dist/index57.js +0 -22
- package/dist/index58.cjs +0 -1
- package/dist/index58.js +0 -34
- package/dist/index59.cjs +0 -1
- package/dist/index59.js +0 -4
- package/dist/index6.cjs +0 -1
- package/dist/index6.js +0 -5
- package/dist/index60.cjs +0 -6
- package/dist/index60.js +0 -949
- package/dist/index61.cjs +0 -1
- package/dist/index61.js +0 -4
- package/dist/index62.cjs +0 -1
- package/dist/index62.js +0 -64
- package/dist/index63.cjs +0 -1
- package/dist/index63.js +0 -35
- package/dist/index64.cjs +0 -1
- package/dist/index64.js +0 -89
- package/dist/index65.cjs +0 -1
- package/dist/index65.js +0 -58
- package/dist/index66.cjs +0 -2
- package/dist/index66.js +0 -62
- package/dist/index67.cjs +0 -1
- package/dist/index67.js +0 -6
- package/dist/index68.cjs +0 -1
- package/dist/index68.js +0 -37
- package/dist/index69.cjs +0 -1
- package/dist/index69.js +0 -130
- package/dist/index7.cjs +0 -1
- package/dist/index7.js +0 -76
- package/dist/index70.cjs +0 -2
- package/dist/index70.js +0 -45
- package/dist/index71.cjs +0 -1
- package/dist/index71.js +0 -11
- package/dist/index72.cjs +0 -1
- package/dist/index72.js +0 -13
- package/dist/index73.cjs +0 -1
- package/dist/index73.js +0 -14
- package/dist/index74.cjs +0 -1
- package/dist/index74.js +0 -16
- package/dist/index75.cjs +0 -1
- package/dist/index75.js +0 -9
- package/dist/index76.cjs +0 -1
- package/dist/index76.js +0 -20
- package/dist/index77.cjs +0 -1
- package/dist/index77.js +0 -81
- package/dist/index78.cjs +0 -1
- package/dist/index78.js +0 -17
- package/dist/index79.cjs +0 -1
- package/dist/index79.js +0 -21
- package/dist/index8.cjs +0 -1
- package/dist/index8.js +0 -61
- package/dist/index80.cjs +0 -1
- package/dist/index80.js +0 -24
- package/dist/index81.cjs +0 -1
- package/dist/index81.js +0 -16
- package/dist/index82.cjs +0 -1
- package/dist/index82.js +0 -9
- package/dist/index83.cjs +0 -1
- package/dist/index83.js +0 -4
- package/dist/index84.cjs +0 -1
- package/dist/index84.js +0 -4
- package/dist/index85.cjs +0 -2
- package/dist/index85.js +0 -37
- package/dist/index86.cjs +0 -1
- package/dist/index86.js +0 -8
- package/dist/index87.cjs +0 -1
- package/dist/index87.js +0 -22
- package/dist/index88.cjs +0 -1
- package/dist/index88.js +0 -37
- package/dist/index89.cjs +0 -1
- package/dist/index89.js +0 -369
- package/dist/index9.cjs +0 -1
- package/dist/index9.js +0 -63
- package/dist/index90.cjs +0 -1
- package/dist/index90.js +0 -23
- package/dist/index91.cjs +0 -1
- package/dist/index91.js +0 -58
- package/dist/index92.cjs +0 -1
- package/dist/index92.js +0 -5
- package/dist/index93.cjs +0 -1
- package/dist/index93.js +0 -51
- package/dist/index94.cjs +0 -1
- package/dist/index94.js +0 -28
- package/dist/index95.cjs +0 -1
- package/dist/index95.js +0 -4
- package/dist/index96.cjs +0 -1
- package/dist/index96.js +0 -4
- package/dist/index97.cjs +0 -1
- package/dist/index97.js +0 -15
- package/dist/index98.cjs +0 -1
- package/dist/index98.js +0 -9
- package/dist/index99.cjs +0 -1
- package/dist/index99.js +0 -115
package/dist/index19.js
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import { chainConfig as a } from "./index25.js";
|
|
2
|
-
import { defineChain as s } from "./index24.js";
|
|
3
|
-
const e = 11155111, o = /* @__PURE__ */ s({
|
|
4
|
-
...a,
|
|
5
|
-
id: 84532,
|
|
6
|
-
network: "base-sepolia",
|
|
7
|
-
name: "Base Sepolia",
|
|
8
|
-
nativeCurrency: { name: "Sepolia Ether", symbol: "ETH", decimals: 18 },
|
|
9
|
-
rpcUrls: {
|
|
10
|
-
default: {
|
|
11
|
-
http: ["https://sepolia.base.org"]
|
|
12
|
-
}
|
|
13
|
-
},
|
|
14
|
-
blockExplorers: {
|
|
15
|
-
default: {
|
|
16
|
-
name: "Basescan",
|
|
17
|
-
url: "https://sepolia.basescan.org",
|
|
18
|
-
apiUrl: "https://api-sepolia.basescan.org/api"
|
|
19
|
-
}
|
|
20
|
-
},
|
|
21
|
-
contracts: {
|
|
22
|
-
...a.contracts,
|
|
23
|
-
disputeGameFactory: {
|
|
24
|
-
[e]: {
|
|
25
|
-
address: "0xd6E6dBf4F7EA0ac412fD8b65ED297e64BB7a06E1"
|
|
26
|
-
}
|
|
27
|
-
},
|
|
28
|
-
l2OutputOracle: {
|
|
29
|
-
[e]: {
|
|
30
|
-
address: "0x84457ca9D0163FbC4bbfe4Dfbb20ba46e48DF254"
|
|
31
|
-
}
|
|
32
|
-
},
|
|
33
|
-
portal: {
|
|
34
|
-
[e]: {
|
|
35
|
-
address: "0x49f53e41452c74589e85ca1677426ba426459e85",
|
|
36
|
-
blockCreated: 4446677
|
|
37
|
-
}
|
|
38
|
-
},
|
|
39
|
-
l1StandardBridge: {
|
|
40
|
-
[e]: {
|
|
41
|
-
address: "0xfd0Bf71F60660E2f608ed56e1659C450eB113120",
|
|
42
|
-
blockCreated: 4446677
|
|
43
|
-
}
|
|
44
|
-
},
|
|
45
|
-
multicall3: {
|
|
46
|
-
address: "0xca11bde05977b3631167028862be2a173976ca11",
|
|
47
|
-
blockCreated: 1059647
|
|
48
|
-
}
|
|
49
|
-
},
|
|
50
|
-
testnet: !0,
|
|
51
|
-
sourceId: e
|
|
52
|
-
});
|
|
53
|
-
export {
|
|
54
|
-
o as baseSepolia
|
|
55
|
-
};
|
package/dist/index2.cjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("@catalogfi/utils"),l=require("./index3.cjs"),o=require("@gardenfi/orderbook"),k=require("@gardenfi/utils"),_=require("./index10.cjs"),p=require("./index7.cjs"),y=require("./index5.cjs"),A=require("./index11.cjs"),g=require("./index12.cjs"),E=require("bignumber.js");class O{constructor(e){if(this.eventListeners=new Map,this.getOrderThreshold=20,this.useRelay=!0,this.orderBook=new o.Orderbook({url:e.orderbookURl,walletClient:e.wallets.evmWallet,auth:e.auth}),this.quote=e.quote,this.secretManager=e.secretManager,this.wallets=e.wallets,this.orderbookUrl=e.orderbookURl,this.auth=e.auth,this.orderExecutorCache=new g.ExecutorCache,!e.wallets.evmWallet.account)throw new Error("Account not found in evmWallet");this.evmAddress=e.wallets.evmWallet.account.address,this.blockNumberFetcher=e.blockNumberFetcher}setUseRelay(e){this.useRelay=e}async swap(e){const t=await this.validateAndFillParams(e);if(t.error)return i.Err(t.error);const{sendAddress:s,receiveAddress:n,timelock:a}=t.val,r=await this.orderBook.getOrdersCount(this.evmAddress);if(r.error)return i.Err(r.error);const h=r.val+1,c=this.secretManager.generateSecret(h);if(c.error)return i.Err(c.error);const{strategyId:d,btcAddress:u}=e.additionalData,f={strategy_id:d,...u&&{bitcoin_optional_recipient:u}},b={source_chain:e.fromAsset.chain,destination_chain:e.toAsset.chain,source_asset:e.fromAsset.atomicSwapAddress,destination_asset:e.toAsset.atomicSwapAddress,initiator_source_address:s,initiator_destination_address:n,source_amount:e.sendAmount,destination_amount:e.receiveAmount,fee:"1",nonce:h.toString(),timelock:a,secret_hash:i.trim0x(c.val.secretHash),min_destination_confirmations:e.minDestinationConfirmations??0,additional_data:f},w=await this.quote.getAttestedQuote(b);if(w.error)return i.Err(w.error);const m=await this.orderBook.createOrder(w.val);if(m.error)return i.Err(m.error);const v=await this.pollOrder(m.val);return v.error?i.Err(v.error):i.Ok(v.val)}async validateAndFillParams(e){if(e.fromAsset.chain===e.toAsset.chain&&e.fromAsset.atomicSwapAddress===e.toAsset.atomicSwapAddress)return i.Err("Source and destination assets cannot be the same");if(o.isMainnet(e.fromAsset.chain)&&!o.isMainnet(e.toAsset.chain)||!o.isMainnet(e.fromAsset.chain)&&o.isMainnet(e.toAsset.chain))return i.Err("Both assets should be on the same network (either mainnet or testnet)");if(o.isBitcoin(e.fromAsset.chain)||o.isBitcoin(e.toAsset.chain)){if(!this.wallets.btcWallet)return i.Err("btcWallet is required for bitcoin chain. Please provide btcWallet in the constructor");if(!e.additionalData.btcAddress)return i.Err("btcAddress in additionalData is required for bitcoin chain")}const t=await this.getAddresses(e.fromAsset.chain);if(t.error)return i.Err(t.error);const s=await this.getAddresses(e.toAsset.chain);if(s.error)return i.Err(s.error);const n=this.validateAmount(e.sendAmount);if(n.error)return i.Err(n.error);const a=this.validateAmount(e.receiveAmount);if(a.error)return i.Err(a.error);if(n<a)return i.Err("Send amount should be greater than receive amount");const r=this.getTimelock(e.fromAsset.chain);return r?i.Ok({sendAddress:t.val,receiveAddress:s.val,timelock:e.timelock??r}):i.Err("Unsupported chain for timelock")}async getAddresses(e){var s;switch(o.getBlockchainType(e)){case o.BlockchainType.EVM:return this.wallets.evmWallet.account?i.Ok(this.wallets.evmWallet.account.address):i.Err("EVM Wallet not found");case o.BlockchainType.Bitcoin:{const n=await((s=this.wallets.btcWallet)==null?void 0:s.getPublicKey());return!n||!_.isValidBitcoinPubKey(n)?i.Err("Invalid btc public key"):i.Ok(_.toXOnly(n))}default:return i.Err("Unsupported chain")}}validateAmount(e){if(e==null||e.includes("."))return i.Err("Invalid amount ",e);const t=new E(e);return!t.isInteger()||t.isNaN()||t.lt(0)||t.isLessThanOrEqualTo(0)?i.Err("Invalid amount ",e):i.Ok(t)}getTimelock(e){switch(o.getBlockchainType(e)){case o.BlockchainType.EVM:return l.TimeLocks.evm;case o.BlockchainType.Bitcoin:return l.TimeLocks.btc;default:return}}async pollOrder(e){let t=await this.orderBook.getOrder(e,!0),s=0;for(;s<this.getOrderThreshold;){if(await k.sleep(1e3),s++,t.error){if(!t.error.includes("result is undefined"))return i.Err(t.error)}else if(t.val&&t.val.create_order.create_id.toLowerCase()===e.toLowerCase())return i.Ok(t.val);t=await this.orderBook.getOrder(e,!0)}return i.Err(`Order not found, createOrder id: ${e}`)}emit(e,...t){(this.eventListeners.get(e)??[]).forEach(n=>{n(...t)})}async execute(e=5e3){return await this.orderBook.subscribeToOrders(!0,e,async t=>{const s=p.filterDeadlineExpiredOrders(t.data),n=await this.assignOrderStatus(s);this.emit("onPendingOrdersChanged",n);for(let a=0;a<n.length;a++){const r=n[a];switch(p.parseActionFromStatus(r.status)){case l.OrderActions.Redeem:{const c=this.secretManager.generateSecret(Number(r.create_order.nonce));if(c.error){this.emit("error",r,c.error);return}switch(o.getBlockchainType(r.destination_swap.chain)){case o.BlockchainType.EVM:{await this.evmRedeem(r,c.val.secret);break}case o.BlockchainType.Bitcoin:{const d=this.getWallet(r.destination_swap.chain);if(d.error){this.emit("error",r,d.error);return}await this.btcRedeem(d.val,r,c.val.secret);break}default:this.emit("error",r,"Unsupported chain: "+r.destination_swap.chain)}break}case l.OrderActions.Refund:{switch(o.getBlockchainType(r.source_swap.chain)){case o.BlockchainType.EVM:{this.emit("error",r,"EVM refund is automatically done by relay service");break}case o.BlockchainType.Bitcoin:{const c=this.getWallet(r.source_swap.chain);if(c.error){this.emit("error",r,c.error);return}await this.btcRefund(c.val,r);break}default:this.emit("error",r,"Unsupported chain: "+r.source_swap.chain)}break}}}},{per_page:500},!0)}async evmRedeem(e,t){if(this.emit("log",e.create_order.create_id,"executing evm redeem"),this.orderExecutorCache.get(e,l.OrderActions.Redeem)){this.emit("log",e.create_order.create_id,"already redeemed");return}const a=await new y.EvmRelay(e,this.orderbookUrl,this.auth).redeem(e.create_order.create_id,t);if(a.error){this.emit("error",e,a.error),a.error.includes("Order already redeemed")&&this.orderExecutorCache.set(e,l.OrderActions.Redeem,e.destination_swap.redeem_tx_hash);return}this.emit("success",e,l.OrderActions.Redeem,a.val),this.orderExecutorCache.set(e,l.OrderActions.Redeem,a.val)}async btcRedeem(e,t,s){var h,c;const n=this.orderExecutorCache.get(t,l.OrderActions.Redeem),a=(h=t.destination_swap.initiate_tx_hash.split(",").at(-1))==null?void 0:h.split(":").at(0);if(!a){this.emit("error",t,"Failed to get initiate_tx_hash");return}let r=!1;if(n)if(n.btcRedeemUTXO&&n.btcRedeemUTXO!==a)r=!0,this.emit("log",t.create_order.create_id,"rbf btc redeem");else{this.emit("log",t.create_order.create_id,"btcRedeem: already redeemed");return}else if(t.destination_swap.redeem_tx_hash&&!Number(t.destination_swap.redeem_block_number))try{const d=await(await e.getProvider()).getTransaction(t.destination_swap.redeem_tx_hash);let u=!1;for(const f of d.vin)if(f.txid===a){u=!0;break}if(u){this.emit("log",t.create_order.create_id,"already a valid redeem"),this.orderExecutorCache.set(t,l.OrderActions.Redeem,t.destination_swap.redeem_tx_hash,a);return}r=!0}catch(d){if(d.message.includes("Transaction not found"))r=!0;else{this.emit("error",t,"Failed to get redeem tx: "+d);return}}this.emit("log",t.create_order.create_id,"executing btc redeem");try{const u=await(await A.GardenHTLC.from(e,Number(t.destination_swap.amount),t.create_order.secret_hash,_.toXOnly(t.destination_swap.initiator),_.toXOnly(t.destination_swap.redeemer),t.destination_swap.timelock,r?[a]:[])).redeem(i.trim0x(s),(c=t.create_order.additional_data)==null?void 0:c.bitcoin_optional_recipient);r?this.emit("log",t.create_order.create_id,"rbf: btc redeem success"):this.emit("success",t,l.OrderActions.Redeem,u),this.orderExecutorCache.set(t,l.OrderActions.Redeem,u,a)}catch(d){this.emit("error",t,"Failed btc redeem: "+d)}}async btcRefund(e,t){var s;if(!this.orderExecutorCache.get(t,l.OrderActions.Refund)){this.emit("log",t.create_order.create_id,"executing btc refund");try{const a=await(await A.GardenHTLC.from(e,Number(t.source_swap.amount),t.create_order.secret_hash,_.toXOnly(t.source_swap.initiator),_.toXOnly(t.source_swap.redeemer),t.source_swap.timelock)).refund((s=t.create_order.additional_data)==null?void 0:s.bitcoin_optional_recipient);this.emit("success",t,l.OrderActions.Refund,a),this.orderExecutorCache.set(t,l.OrderActions.Refund,a)}catch(n){this.emit("error",t,"Failed btc refund: "+n)}}}getWallet(e){switch(o.getBlockchainType(e)){case o.BlockchainType.EVM:return i.Ok(this.wallets.evmWallet);case o.BlockchainType.Bitcoin:return i.Ok(this.wallets.btcWallet);default:return i.Err("Unsupported chain for wallet")}}on(e,t){const s=this.eventListeners.get(e)??[];s.push(t),this.eventListeners.set(e,s)}off(e,t){const s=this.eventListeners.get(e)??[],n=s.indexOf(t);n!==-1&&s.splice(n,1)}async fetchCurrentBlockNumbers(e,t){if(!t||!t.source||!t.destination)return i.Err("Provide wallets to fetch the current block number");const s=o.isBitcoin(e.source_swap.chain)?await k.fetchBitcoinBlockNumber(await t.source.getProvider()):await k.fetchEVMBlockNumber(t.source);if(s.error)return i.Err(s.error);const n=o.isBitcoin(e.destination_swap.chain)?await k.fetchBitcoinBlockNumber(await t.destination.getProvider()):await k.fetchEVMBlockNumber(t.destination);return n.error?i.Err(n.error):i.Ok({source:s.val,destination:n.val})}async assignOrderStatus(e){var n;const t=await((n=this.blockNumberFetcher)==null?void 0:n.fetchBlockNumbers()),s=[];for(let a=0;a<e.length;a++){const r=e[a],h=r.source_swap.chain,c=r.destination_swap.chain,d=this.getWallet(h),u=this.getWallet(c);if(d.error||u.error||!d.val||!u.val){this.emit("error",r,"Source or Destination Wallet not found while executing order");continue}let f=t==null?void 0:t.val[h],b=t==null?void 0:t.val[c];if(!f||!b){const m=await this.fetchCurrentBlockNumbers(r,{source:d.val,destination:u.val});if(m.error){this.emit("error",r,"Error while fetching CurrentBlockNumbers: "+m.error);continue}f=m.val.source,b=m.val.destination}const w=p.ParseOrderStatus(r,f,b);s.push({...r,status:w})}return s}}exports.Garden=O;
|
package/dist/index2.js
DELETED
|
@@ -1,412 +0,0 @@
|
|
|
1
|
-
import { Err as o, trim0x as y, Ok as m } from "@catalogfi/utils";
|
|
2
|
-
import { TimeLocks as R, OrderActions as d } from "./index3.js";
|
|
3
|
-
import { Orderbook as E, isMainnet as g, isBitcoin as k, getBlockchainType as v, BlockchainType as u } from "@gardenfi/orderbook";
|
|
4
|
-
import { sleep as W, fetchBitcoinBlockNumber as x, fetchEVMBlockNumber as C } from "@gardenfi/utils";
|
|
5
|
-
import { isValidBitcoinPubKey as O, toXOnly as p } from "./index10.js";
|
|
6
|
-
import { filterDeadlineExpiredOrders as T, parseActionFromStatus as N, ParseOrderStatus as S } from "./index7.js";
|
|
7
|
-
import { EvmRelay as M } from "./index5.js";
|
|
8
|
-
import { GardenHTLC as B } from "./index11.js";
|
|
9
|
-
import { ExecutorCache as U } from "./index12.js";
|
|
10
|
-
import P from "bignumber.js";
|
|
11
|
-
class $ {
|
|
12
|
-
constructor(e) {
|
|
13
|
-
if (this.eventListeners = /* @__PURE__ */ new Map(), this.getOrderThreshold = 20, this.useRelay = !0, this.orderBook = new E({
|
|
14
|
-
url: e.orderbookURl,
|
|
15
|
-
walletClient: e.wallets.evmWallet,
|
|
16
|
-
auth: e.auth
|
|
17
|
-
}), this.quote = e.quote, this.secretManager = e.secretManager, this.wallets = e.wallets, this.orderbookUrl = e.orderbookURl, this.auth = e.auth, this.orderExecutorCache = new U(), !e.wallets.evmWallet.account)
|
|
18
|
-
throw new Error("Account not found in evmWallet");
|
|
19
|
-
this.evmAddress = e.wallets.evmWallet.account.address, this.blockNumberFetcher = e.blockNumberFetcher;
|
|
20
|
-
}
|
|
21
|
-
setUseRelay(e) {
|
|
22
|
-
this.useRelay = e;
|
|
23
|
-
}
|
|
24
|
-
async swap(e) {
|
|
25
|
-
const t = await this.validateAndFillParams(e);
|
|
26
|
-
if (t.error) return o(t.error);
|
|
27
|
-
const { sendAddress: i, receiveAddress: s, timelock: a } = t.val, r = await this.orderBook.getOrdersCount(this.evmAddress);
|
|
28
|
-
if (r.error) return o(r.error);
|
|
29
|
-
const h = r.val + 1, n = this.secretManager.generateSecret(h);
|
|
30
|
-
if (n.error) return o(n.error);
|
|
31
|
-
const { strategyId: c, btcAddress: l } = e.additionalData, _ = {
|
|
32
|
-
strategy_id: c,
|
|
33
|
-
...l && {
|
|
34
|
-
bitcoin_optional_recipient: l
|
|
35
|
-
}
|
|
36
|
-
}, w = {
|
|
37
|
-
source_chain: e.fromAsset.chain,
|
|
38
|
-
destination_chain: e.toAsset.chain,
|
|
39
|
-
source_asset: e.fromAsset.atomicSwapAddress,
|
|
40
|
-
destination_asset: e.toAsset.atomicSwapAddress,
|
|
41
|
-
initiator_source_address: i,
|
|
42
|
-
initiator_destination_address: s,
|
|
43
|
-
source_amount: e.sendAmount,
|
|
44
|
-
destination_amount: e.receiveAmount,
|
|
45
|
-
fee: "1",
|
|
46
|
-
nonce: h.toString(),
|
|
47
|
-
timelock: a,
|
|
48
|
-
secret_hash: y(n.val.secretHash),
|
|
49
|
-
min_destination_confirmations: e.minDestinationConfirmations ?? 0,
|
|
50
|
-
additional_data: _
|
|
51
|
-
}, b = await this.quote.getAttestedQuote(w);
|
|
52
|
-
if (b.error) return o(b.error);
|
|
53
|
-
const f = await this.orderBook.createOrder(b.val);
|
|
54
|
-
if (f.error) return o(f.error);
|
|
55
|
-
const A = await this.pollOrder(f.val);
|
|
56
|
-
return A.error ? o(A.error) : m(A.val);
|
|
57
|
-
}
|
|
58
|
-
async validateAndFillParams(e) {
|
|
59
|
-
if (e.fromAsset.chain === e.toAsset.chain && e.fromAsset.atomicSwapAddress === e.toAsset.atomicSwapAddress)
|
|
60
|
-
return o("Source and destination assets cannot be the same");
|
|
61
|
-
if (g(e.fromAsset.chain) && !g(e.toAsset.chain) || !g(e.fromAsset.chain) && g(e.toAsset.chain))
|
|
62
|
-
return o(
|
|
63
|
-
"Both assets should be on the same network (either mainnet or testnet)"
|
|
64
|
-
);
|
|
65
|
-
if (k(e.fromAsset.chain) || k(e.toAsset.chain)) {
|
|
66
|
-
if (!this.wallets.btcWallet)
|
|
67
|
-
return o(
|
|
68
|
-
"btcWallet is required for bitcoin chain. Please provide btcWallet in the constructor"
|
|
69
|
-
);
|
|
70
|
-
if (!e.additionalData.btcAddress)
|
|
71
|
-
return o(
|
|
72
|
-
"btcAddress in additionalData is required for bitcoin chain"
|
|
73
|
-
);
|
|
74
|
-
}
|
|
75
|
-
const t = await this.getAddresses(e.fromAsset.chain);
|
|
76
|
-
if (t.error) return o(t.error);
|
|
77
|
-
const i = await this.getAddresses(e.toAsset.chain);
|
|
78
|
-
if (i.error) return o(i.error);
|
|
79
|
-
const s = this.validateAmount(e.sendAmount);
|
|
80
|
-
if (s.error) return o(s.error);
|
|
81
|
-
const a = this.validateAmount(e.receiveAmount);
|
|
82
|
-
if (a.error) return o(a.error);
|
|
83
|
-
if (s < a)
|
|
84
|
-
return o("Send amount should be greater than receive amount");
|
|
85
|
-
const r = this.getTimelock(e.fromAsset.chain);
|
|
86
|
-
return r ? m({
|
|
87
|
-
sendAddress: t.val,
|
|
88
|
-
receiveAddress: i.val,
|
|
89
|
-
timelock: e.timelock ?? r
|
|
90
|
-
}) : o("Unsupported chain for timelock");
|
|
91
|
-
}
|
|
92
|
-
async getAddresses(e) {
|
|
93
|
-
var i;
|
|
94
|
-
switch (v(e)) {
|
|
95
|
-
case u.EVM:
|
|
96
|
-
return this.wallets.evmWallet.account ? m(this.wallets.evmWallet.account.address) : o("EVM Wallet not found");
|
|
97
|
-
case u.Bitcoin: {
|
|
98
|
-
const s = await ((i = this.wallets.btcWallet) == null ? void 0 : i.getPublicKey());
|
|
99
|
-
return !s || !O(s) ? o("Invalid btc public key") : m(p(s));
|
|
100
|
-
}
|
|
101
|
-
default:
|
|
102
|
-
return o("Unsupported chain");
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
validateAmount(e) {
|
|
106
|
-
if (e == null || e.includes("."))
|
|
107
|
-
return o("Invalid amount ", e);
|
|
108
|
-
const t = new P(e);
|
|
109
|
-
return !t.isInteger() || t.isNaN() || t.lt(0) || t.isLessThanOrEqualTo(0) ? o("Invalid amount ", e) : m(t);
|
|
110
|
-
}
|
|
111
|
-
getTimelock(e) {
|
|
112
|
-
switch (v(e)) {
|
|
113
|
-
case u.EVM:
|
|
114
|
-
return R.evm;
|
|
115
|
-
case u.Bitcoin:
|
|
116
|
-
return R.btc;
|
|
117
|
-
default:
|
|
118
|
-
return;
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
async pollOrder(e) {
|
|
122
|
-
let t = await this.orderBook.getOrder(e, !0), i = 0;
|
|
123
|
-
for (; i < this.getOrderThreshold; ) {
|
|
124
|
-
if (await W(1e3), i++, t.error) {
|
|
125
|
-
if (!t.error.includes("result is undefined"))
|
|
126
|
-
return o(t.error);
|
|
127
|
-
} else if (t.val && t.val.create_order.create_id.toLowerCase() === e.toLowerCase())
|
|
128
|
-
return m(t.val);
|
|
129
|
-
t = await this.orderBook.getOrder(e, !0);
|
|
130
|
-
}
|
|
131
|
-
return o(`Order not found, createOrder id: ${e}`);
|
|
132
|
-
}
|
|
133
|
-
emit(e, ...t) {
|
|
134
|
-
(this.eventListeners.get(e) ?? []).forEach((s) => {
|
|
135
|
-
s(...t);
|
|
136
|
-
});
|
|
137
|
-
}
|
|
138
|
-
async execute(e = 5e3) {
|
|
139
|
-
return await this.orderBook.subscribeToOrders(
|
|
140
|
-
!0,
|
|
141
|
-
e,
|
|
142
|
-
async (t) => {
|
|
143
|
-
const i = T(t.data), s = await this.assignOrderStatus(i);
|
|
144
|
-
this.emit("onPendingOrdersChanged", s);
|
|
145
|
-
for (let a = 0; a < s.length; a++) {
|
|
146
|
-
const r = s[a];
|
|
147
|
-
switch (N(r.status)) {
|
|
148
|
-
case d.Redeem: {
|
|
149
|
-
const n = this.secretManager.generateSecret(
|
|
150
|
-
Number(r.create_order.nonce)
|
|
151
|
-
);
|
|
152
|
-
if (n.error) {
|
|
153
|
-
this.emit("error", r, n.error);
|
|
154
|
-
return;
|
|
155
|
-
}
|
|
156
|
-
switch (v(r.destination_swap.chain)) {
|
|
157
|
-
case u.EVM: {
|
|
158
|
-
await this.evmRedeem(r, n.val.secret);
|
|
159
|
-
break;
|
|
160
|
-
}
|
|
161
|
-
case u.Bitcoin: {
|
|
162
|
-
const c = this.getWallet(
|
|
163
|
-
r.destination_swap.chain
|
|
164
|
-
);
|
|
165
|
-
if (c.error) {
|
|
166
|
-
this.emit("error", r, c.error);
|
|
167
|
-
return;
|
|
168
|
-
}
|
|
169
|
-
await this.btcRedeem(
|
|
170
|
-
c.val,
|
|
171
|
-
r,
|
|
172
|
-
n.val.secret
|
|
173
|
-
);
|
|
174
|
-
break;
|
|
175
|
-
}
|
|
176
|
-
default:
|
|
177
|
-
this.emit(
|
|
178
|
-
"error",
|
|
179
|
-
r,
|
|
180
|
-
"Unsupported chain: " + r.destination_swap.chain
|
|
181
|
-
);
|
|
182
|
-
}
|
|
183
|
-
break;
|
|
184
|
-
}
|
|
185
|
-
case d.Refund: {
|
|
186
|
-
switch (v(r.source_swap.chain)) {
|
|
187
|
-
case u.EVM: {
|
|
188
|
-
this.emit(
|
|
189
|
-
"error",
|
|
190
|
-
r,
|
|
191
|
-
"EVM refund is automatically done by relay service"
|
|
192
|
-
);
|
|
193
|
-
break;
|
|
194
|
-
}
|
|
195
|
-
case u.Bitcoin: {
|
|
196
|
-
const n = this.getWallet(r.source_swap.chain);
|
|
197
|
-
if (n.error) {
|
|
198
|
-
this.emit("error", r, n.error);
|
|
199
|
-
return;
|
|
200
|
-
}
|
|
201
|
-
await this.btcRefund(
|
|
202
|
-
n.val,
|
|
203
|
-
r
|
|
204
|
-
);
|
|
205
|
-
break;
|
|
206
|
-
}
|
|
207
|
-
default:
|
|
208
|
-
this.emit(
|
|
209
|
-
"error",
|
|
210
|
-
r,
|
|
211
|
-
"Unsupported chain: " + r.source_swap.chain
|
|
212
|
-
);
|
|
213
|
-
}
|
|
214
|
-
break;
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
},
|
|
219
|
-
{
|
|
220
|
-
per_page: 500
|
|
221
|
-
},
|
|
222
|
-
!0
|
|
223
|
-
);
|
|
224
|
-
}
|
|
225
|
-
async evmRedeem(e, t) {
|
|
226
|
-
if (this.emit("log", e.create_order.create_id, "executing evm redeem"), this.orderExecutorCache.get(e, d.Redeem)) {
|
|
227
|
-
this.emit("log", e.create_order.create_id, "already redeemed");
|
|
228
|
-
return;
|
|
229
|
-
}
|
|
230
|
-
const a = await new M(e, this.orderbookUrl, this.auth).redeem(e.create_order.create_id, t);
|
|
231
|
-
if (a.error) {
|
|
232
|
-
this.emit("error", e, a.error), a.error.includes("Order already redeemed") && this.orderExecutorCache.set(
|
|
233
|
-
e,
|
|
234
|
-
d.Redeem,
|
|
235
|
-
e.destination_swap.redeem_tx_hash
|
|
236
|
-
);
|
|
237
|
-
return;
|
|
238
|
-
}
|
|
239
|
-
this.emit("success", e, d.Redeem, a.val), this.orderExecutorCache.set(e, d.Redeem, a.val);
|
|
240
|
-
}
|
|
241
|
-
async btcRedeem(e, t, i) {
|
|
242
|
-
var h, n;
|
|
243
|
-
const s = this.orderExecutorCache.get(t, d.Redeem), a = (h = t.destination_swap.initiate_tx_hash.split(",").at(-1)) == null ? void 0 : h.split(":").at(0);
|
|
244
|
-
if (!a) {
|
|
245
|
-
this.emit("error", t, "Failed to get initiate_tx_hash");
|
|
246
|
-
return;
|
|
247
|
-
}
|
|
248
|
-
let r = !1;
|
|
249
|
-
if (s)
|
|
250
|
-
if (s.btcRedeemUTXO && s.btcRedeemUTXO !== a)
|
|
251
|
-
r = !0, this.emit("log", t.create_order.create_id, "rbf btc redeem");
|
|
252
|
-
else {
|
|
253
|
-
this.emit(
|
|
254
|
-
"log",
|
|
255
|
-
t.create_order.create_id,
|
|
256
|
-
"btcRedeem: already redeemed"
|
|
257
|
-
);
|
|
258
|
-
return;
|
|
259
|
-
}
|
|
260
|
-
else if (t.destination_swap.redeem_tx_hash && !Number(t.destination_swap.redeem_block_number))
|
|
261
|
-
try {
|
|
262
|
-
const c = await (await e.getProvider()).getTransaction(t.destination_swap.redeem_tx_hash);
|
|
263
|
-
let l = !1;
|
|
264
|
-
for (const _ of c.vin)
|
|
265
|
-
if (_.txid === a) {
|
|
266
|
-
l = !0;
|
|
267
|
-
break;
|
|
268
|
-
}
|
|
269
|
-
if (l) {
|
|
270
|
-
this.emit(
|
|
271
|
-
"log",
|
|
272
|
-
t.create_order.create_id,
|
|
273
|
-
"already a valid redeem"
|
|
274
|
-
), this.orderExecutorCache.set(
|
|
275
|
-
t,
|
|
276
|
-
d.Redeem,
|
|
277
|
-
t.destination_swap.redeem_tx_hash,
|
|
278
|
-
a
|
|
279
|
-
);
|
|
280
|
-
return;
|
|
281
|
-
}
|
|
282
|
-
r = !0;
|
|
283
|
-
} catch (c) {
|
|
284
|
-
if (c.message.includes("Transaction not found"))
|
|
285
|
-
r = !0;
|
|
286
|
-
else {
|
|
287
|
-
this.emit("error", t, "Failed to get redeem tx: " + c);
|
|
288
|
-
return;
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
this.emit("log", t.create_order.create_id, "executing btc redeem");
|
|
292
|
-
try {
|
|
293
|
-
const l = await (await B.from(
|
|
294
|
-
e,
|
|
295
|
-
Number(t.destination_swap.amount),
|
|
296
|
-
t.create_order.secret_hash,
|
|
297
|
-
p(t.destination_swap.initiator),
|
|
298
|
-
p(t.destination_swap.redeemer),
|
|
299
|
-
t.destination_swap.timelock,
|
|
300
|
-
r ? [a] : []
|
|
301
|
-
)).redeem(
|
|
302
|
-
y(i),
|
|
303
|
-
(n = t.create_order.additional_data) == null ? void 0 : n.bitcoin_optional_recipient
|
|
304
|
-
);
|
|
305
|
-
r ? this.emit(
|
|
306
|
-
"log",
|
|
307
|
-
t.create_order.create_id,
|
|
308
|
-
"rbf: btc redeem success"
|
|
309
|
-
) : this.emit("success", t, d.Redeem, l), this.orderExecutorCache.set(t, d.Redeem, l, a);
|
|
310
|
-
} catch (c) {
|
|
311
|
-
this.emit("error", t, "Failed btc redeem: " + c);
|
|
312
|
-
}
|
|
313
|
-
}
|
|
314
|
-
async btcRefund(e, t) {
|
|
315
|
-
var i;
|
|
316
|
-
if (!this.orderExecutorCache.get(t, d.Refund)) {
|
|
317
|
-
this.emit("log", t.create_order.create_id, "executing btc refund");
|
|
318
|
-
try {
|
|
319
|
-
const a = await (await B.from(
|
|
320
|
-
e,
|
|
321
|
-
Number(t.source_swap.amount),
|
|
322
|
-
t.create_order.secret_hash,
|
|
323
|
-
p(t.source_swap.initiator),
|
|
324
|
-
p(t.source_swap.redeemer),
|
|
325
|
-
t.source_swap.timelock
|
|
326
|
-
)).refund(
|
|
327
|
-
(i = t.create_order.additional_data) == null ? void 0 : i.bitcoin_optional_recipient
|
|
328
|
-
);
|
|
329
|
-
this.emit("success", t, d.Refund, a), this.orderExecutorCache.set(t, d.Refund, a);
|
|
330
|
-
} catch (s) {
|
|
331
|
-
this.emit("error", t, "Failed btc refund: " + s);
|
|
332
|
-
}
|
|
333
|
-
}
|
|
334
|
-
}
|
|
335
|
-
getWallet(e) {
|
|
336
|
-
switch (v(e)) {
|
|
337
|
-
case u.EVM:
|
|
338
|
-
return m(this.wallets.evmWallet);
|
|
339
|
-
case u.Bitcoin:
|
|
340
|
-
return m(this.wallets.btcWallet);
|
|
341
|
-
default:
|
|
342
|
-
return o("Unsupported chain for wallet");
|
|
343
|
-
}
|
|
344
|
-
}
|
|
345
|
-
on(e, t) {
|
|
346
|
-
const i = this.eventListeners.get(e) ?? [];
|
|
347
|
-
i.push(t), this.eventListeners.set(e, i);
|
|
348
|
-
}
|
|
349
|
-
off(e, t) {
|
|
350
|
-
const i = this.eventListeners.get(e) ?? [], s = i.indexOf(t);
|
|
351
|
-
s !== -1 && i.splice(s, 1);
|
|
352
|
-
}
|
|
353
|
-
async fetchCurrentBlockNumbers(e, t) {
|
|
354
|
-
if (!t || !t.source || !t.destination)
|
|
355
|
-
return o("Provide wallets to fetch the current block number");
|
|
356
|
-
const i = k(e.source_swap.chain) ? await x(
|
|
357
|
-
await t.source.getProvider()
|
|
358
|
-
) : await C(t.source);
|
|
359
|
-
if (i.error) return o(i.error);
|
|
360
|
-
const s = k(e.destination_swap.chain) ? await x(
|
|
361
|
-
await t.destination.getProvider()
|
|
362
|
-
) : await C(t.destination);
|
|
363
|
-
return s.error ? o(s.error) : m({
|
|
364
|
-
source: i.val,
|
|
365
|
-
destination: s.val
|
|
366
|
-
});
|
|
367
|
-
}
|
|
368
|
-
async assignOrderStatus(e) {
|
|
369
|
-
var s;
|
|
370
|
-
const t = await ((s = this.blockNumberFetcher) == null ? void 0 : s.fetchBlockNumbers()), i = [];
|
|
371
|
-
for (let a = 0; a < e.length; a++) {
|
|
372
|
-
const r = e[a], h = r.source_swap.chain, n = r.destination_swap.chain, c = this.getWallet(h), l = this.getWallet(n);
|
|
373
|
-
if (c.error || l.error || !c.val || !l.val) {
|
|
374
|
-
this.emit(
|
|
375
|
-
"error",
|
|
376
|
-
r,
|
|
377
|
-
"Source or Destination Wallet not found while executing order"
|
|
378
|
-
);
|
|
379
|
-
continue;
|
|
380
|
-
}
|
|
381
|
-
let _ = t == null ? void 0 : t.val[h], w = t == null ? void 0 : t.val[n];
|
|
382
|
-
if (!_ || !w) {
|
|
383
|
-
const f = await this.fetchCurrentBlockNumbers(r, {
|
|
384
|
-
source: c.val,
|
|
385
|
-
destination: l.val
|
|
386
|
-
});
|
|
387
|
-
if (f.error) {
|
|
388
|
-
this.emit(
|
|
389
|
-
"error",
|
|
390
|
-
r,
|
|
391
|
-
"Error while fetching CurrentBlockNumbers: " + f.error
|
|
392
|
-
);
|
|
393
|
-
continue;
|
|
394
|
-
}
|
|
395
|
-
_ = f.val.source, w = f.val.destination;
|
|
396
|
-
}
|
|
397
|
-
const b = S(
|
|
398
|
-
r,
|
|
399
|
-
_,
|
|
400
|
-
w
|
|
401
|
-
);
|
|
402
|
-
i.push({
|
|
403
|
-
...r,
|
|
404
|
-
status: b
|
|
405
|
-
});
|
|
406
|
-
}
|
|
407
|
-
return i;
|
|
408
|
-
}
|
|
409
|
-
}
|
|
410
|
-
export {
|
|
411
|
-
$ as Garden
|
|
412
|
-
};
|
package/dist/index20.cjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var u=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function f(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function l(e){if(e.__esModule)return e;var r=e.default;if(typeof r=="function"){var t=function o(){return this instanceof o?Reflect.construct(r,arguments,this.constructor):r.apply(this,arguments)};t.prototype=r.prototype}else t={};return Object.defineProperty(t,"__esModule",{value:!0}),Object.keys(e).forEach(function(o){var n=Object.getOwnPropertyDescriptor(e,o);Object.defineProperty(t,o,n.get?n:{enumerable:!0,get:function(){return e[o]}})}),t}exports.commonjsGlobal=u;exports.getAugmentedNamespace=l;exports.getDefaultExportFromCjs=f;
|
package/dist/index20.js
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
var u = typeof globalThis < "u" ? globalThis : typeof window < "u" ? window : typeof global < "u" ? global : typeof self < "u" ? self : {};
|
|
2
|
-
function f(e) {
|
|
3
|
-
return e && e.__esModule && Object.prototype.hasOwnProperty.call(e, "default") ? e.default : e;
|
|
4
|
-
}
|
|
5
|
-
function l(e) {
|
|
6
|
-
if (e.__esModule) return e;
|
|
7
|
-
var r = e.default;
|
|
8
|
-
if (typeof r == "function") {
|
|
9
|
-
var t = function o() {
|
|
10
|
-
return this instanceof o ? Reflect.construct(r, arguments, this.constructor) : r.apply(this, arguments);
|
|
11
|
-
};
|
|
12
|
-
t.prototype = r.prototype;
|
|
13
|
-
} else t = {};
|
|
14
|
-
return Object.defineProperty(t, "__esModule", { value: !0 }), Object.keys(e).forEach(function(o) {
|
|
15
|
-
var n = Object.getOwnPropertyDescriptor(e, o);
|
|
16
|
-
Object.defineProperty(t, o, n.get ? n : {
|
|
17
|
-
enumerable: !0,
|
|
18
|
-
get: function() {
|
|
19
|
-
return e[o];
|
|
20
|
-
}
|
|
21
|
-
});
|
|
22
|
-
}), t;
|
|
23
|
-
}
|
|
24
|
-
export {
|
|
25
|
-
u as commonjsGlobal,
|
|
26
|
-
l as getAugmentedNamespace,
|
|
27
|
-
f as getDefaultExportFromCjs
|
|
28
|
-
};
|
package/dist/index21.cjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var e={};exports.__exports=e;
|
package/dist/index21.js
DELETED
package/dist/index22.cjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";var v=Object.defineProperty;var k=(r,o,f)=>o in r?v(r,o,{enumerable:!0,configurable:!0,writable:!0,value:f}):r[o]=f;var a=(r,o,f)=>k(r,typeof o!="symbol"?o+"":o,f);const c=require("./index23.cjs");require("./index26.cjs");require("./index27.cjs");const b=require("./index28.cjs"),P=require("./index29.cjs");require("./index30.cjs");const K=require("./index31.cjs"),x=require("./index32.cjs"),g=require("./index33.cjs");Object.defineProperty(c.__exports,"__esModule",{value:!0});c.__exports.ECPairFactory=c.__exports.networks=void 0;const p=K.__exports;c.__exports.networks=p;const n=x.__exports,E=b.browserExports,_=P.wif,B=g.__exports,y=n.typeforce.maybe(n.typeforce.compile({compressed:n.maybe(n.Boolean),network:n.maybe(n.Network)})),D=r=>r.length===32?r:r.slice(1,33);function F(r){(0,B.testEcc)(r);function o(s){return r.isPoint(s)}function f(s,e){if(n.typeforce(n.Buffer256bit,s),!r.isPrivate(s))throw new TypeError("Private key not in range [1, n)");return n.typeforce(y,e),new d(s,void 0,e)}function h(s,e){return n.typeforce(r.isPoint,s),n.typeforce(y,e),new d(void 0,s,e)}function l(s,e){const t=_.decode(s),i=t.version;if(n.Array(e)){if(e=e.filter(u=>i===u.wif).pop(),!e)throw new Error("Unknown network version")}else if(e=e||p.bitcoin,i!==e.wif)throw new Error("Invalid network version");return f(t.privateKey,{compressed:t.compressed,network:e})}function m(s){n.typeforce(y,s),s===void 0&&(s={});const e=s.rng||E;let t;do t=e(32),n.typeforce(n.Buffer256bit,t);while(!r.isPrivate(t));return f(t,s)}class d{constructor(e,t,i){a(this,"__D");a(this,"__Q");a(this,"compressed");a(this,"network");a(this,"lowR");this.__D=e,this.__Q=t,this.lowR=!1,i===void 0&&(i={}),this.compressed=i.compressed===void 0?!0:i.compressed,this.network=i.network||p.bitcoin,t!==void 0&&(this.__Q=Buffer.from(r.pointCompress(t,this.compressed)))}get privateKey(){return this.__D}get publicKey(){if(!this.__Q){const e=r.pointFromScalar(this.__D,this.compressed);this.__Q=Buffer.from(e)}return this.__Q}toWIF(){if(!this.__D)throw new Error("Missing private key");return _.encode(this.network.wif,this.__D,this.compressed)}tweak(e){return this.privateKey?this.tweakFromPrivateKey(e):this.tweakFromPublicKey(e)}sign(e,t){if(!this.__D)throw new Error("Missing private key");if(t===void 0&&(t=this.lowR),t===!1)return Buffer.from(r.sign(e,this.__D));{let i=r.sign(e,this.__D);const u=Buffer.alloc(32,0);let w=0;for(;i[0]>127;)w++,u.writeUIntLE(w,0,6),i=r.sign(e,this.__D,u);return Buffer.from(i)}}signSchnorr(e){if(!this.privateKey)throw new Error("Missing private key");if(!r.signSchnorr)throw new Error("signSchnorr not supported by ecc library");return Buffer.from(r.signSchnorr(e,this.privateKey))}verify(e,t){return r.verify(e,this.publicKey,t)}verifySchnorr(e,t){if(!r.verifySchnorr)throw new Error("verifySchnorr not supported by ecc library");return r.verifySchnorr(e,this.publicKey.subarray(1,33),t)}tweakFromPublicKey(e){const t=D(this.publicKey),i=r.xOnlyPointAddTweak(t,e);if(!i||i.xOnlyPubkey===null)throw new Error("Cannot tweak public key!");const u=Buffer.from([i.parity===0?2:3]);return h(Buffer.concat([u,i.xOnlyPubkey]),{network:this.network,compressed:this.compressed})}tweakFromPrivateKey(e){const i=this.publicKey[0]===3||this.publicKey[0]===4&&(this.publicKey[64]&1)===1?r.privateNegate(this.privateKey):this.privateKey,u=r.privateAdd(i,e);if(!u)throw new Error("Invalid tweaked private key!");return f(Buffer.from(u),{network:this.network,compressed:this.compressed})}}return{isPoint:o,fromPrivateKey:f,fromPublicKey:h,fromWIF:l,makeRandom:m}}c.__exports.ECPairFactory=F;module.exports=c.__exports;
|
package/dist/index22.js
DELETED
|
@@ -1,140 +0,0 @@
|
|
|
1
|
-
var v = Object.defineProperty;
|
|
2
|
-
var k = (e, n, f) => n in e ? v(e, n, { enumerable: !0, configurable: !0, writable: !0, value: f }) : e[n] = f;
|
|
3
|
-
var y = (e, n, f) => k(e, typeof n != "symbol" ? n + "" : n, f);
|
|
4
|
-
import { __exports as p } from "./index23.js";
|
|
5
|
-
import "./index26.js";
|
|
6
|
-
import "./index27.js";
|
|
7
|
-
import { b } from "./index28.js";
|
|
8
|
-
import { w as P } from "./index29.js";
|
|
9
|
-
import "./index30.js";
|
|
10
|
-
import { __exports as K } from "./index31.js";
|
|
11
|
-
import { __exports as g } from "./index32.js";
|
|
12
|
-
import { __exports as E } from "./index33.js";
|
|
13
|
-
Object.defineProperty(p, "__esModule", { value: !0 });
|
|
14
|
-
p.ECPairFactory = p.networks = void 0;
|
|
15
|
-
const c = K;
|
|
16
|
-
p.networks = c;
|
|
17
|
-
const s = g, x = b, m = P, B = E, u = s.typeforce.maybe(
|
|
18
|
-
s.typeforce.compile({
|
|
19
|
-
compressed: s.maybe(s.Boolean),
|
|
20
|
-
network: s.maybe(s.Network)
|
|
21
|
-
})
|
|
22
|
-
), D = (e) => e.length === 32 ? e : e.slice(1, 33);
|
|
23
|
-
function F(e) {
|
|
24
|
-
(0, B.testEcc)(e);
|
|
25
|
-
function n(o) {
|
|
26
|
-
return e.isPoint(o);
|
|
27
|
-
}
|
|
28
|
-
function f(o, r) {
|
|
29
|
-
if (s.typeforce(s.Buffer256bit, o), !e.isPrivate(o))
|
|
30
|
-
throw new TypeError("Private key not in range [1, n)");
|
|
31
|
-
return s.typeforce(u, r), new d(o, void 0, r);
|
|
32
|
-
}
|
|
33
|
-
function h(o, r) {
|
|
34
|
-
return s.typeforce(e.isPoint, o), s.typeforce(u, r), new d(void 0, o, r);
|
|
35
|
-
}
|
|
36
|
-
function l(o, r) {
|
|
37
|
-
const t = m.decode(o), i = t.version;
|
|
38
|
-
if (s.Array(r)) {
|
|
39
|
-
if (r = r.filter((a) => i === a.wif).pop(), !r) throw new Error("Unknown network version");
|
|
40
|
-
} else if (r = r || c.bitcoin, i !== r.wif) throw new Error("Invalid network version");
|
|
41
|
-
return f(t.privateKey, {
|
|
42
|
-
compressed: t.compressed,
|
|
43
|
-
network: r
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
function _(o) {
|
|
47
|
-
s.typeforce(u, o), o === void 0 && (o = {});
|
|
48
|
-
const r = o.rng || x;
|
|
49
|
-
let t;
|
|
50
|
-
do
|
|
51
|
-
t = r(32), s.typeforce(s.Buffer256bit, t);
|
|
52
|
-
while (!e.isPrivate(t));
|
|
53
|
-
return f(t, o);
|
|
54
|
-
}
|
|
55
|
-
class d {
|
|
56
|
-
constructor(r, t, i) {
|
|
57
|
-
y(this, "__D");
|
|
58
|
-
y(this, "__Q");
|
|
59
|
-
y(this, "compressed");
|
|
60
|
-
y(this, "network");
|
|
61
|
-
y(this, "lowR");
|
|
62
|
-
this.__D = r, this.__Q = t, this.lowR = !1, i === void 0 && (i = {}), this.compressed = i.compressed === void 0 ? !0 : i.compressed, this.network = i.network || c.bitcoin, t !== void 0 && (this.__Q = Buffer.from(e.pointCompress(t, this.compressed)));
|
|
63
|
-
}
|
|
64
|
-
get privateKey() {
|
|
65
|
-
return this.__D;
|
|
66
|
-
}
|
|
67
|
-
get publicKey() {
|
|
68
|
-
if (!this.__Q) {
|
|
69
|
-
const r = e.pointFromScalar(this.__D, this.compressed);
|
|
70
|
-
this.__Q = Buffer.from(r);
|
|
71
|
-
}
|
|
72
|
-
return this.__Q;
|
|
73
|
-
}
|
|
74
|
-
toWIF() {
|
|
75
|
-
if (!this.__D) throw new Error("Missing private key");
|
|
76
|
-
return m.encode(this.network.wif, this.__D, this.compressed);
|
|
77
|
-
}
|
|
78
|
-
tweak(r) {
|
|
79
|
-
return this.privateKey ? this.tweakFromPrivateKey(r) : this.tweakFromPublicKey(r);
|
|
80
|
-
}
|
|
81
|
-
sign(r, t) {
|
|
82
|
-
if (!this.__D) throw new Error("Missing private key");
|
|
83
|
-
if (t === void 0 && (t = this.lowR), t === !1)
|
|
84
|
-
return Buffer.from(e.sign(r, this.__D));
|
|
85
|
-
{
|
|
86
|
-
let i = e.sign(r, this.__D);
|
|
87
|
-
const a = Buffer.alloc(32, 0);
|
|
88
|
-
let w = 0;
|
|
89
|
-
for (; i[0] > 127; )
|
|
90
|
-
w++, a.writeUIntLE(w, 0, 6), i = e.sign(r, this.__D, a);
|
|
91
|
-
return Buffer.from(i);
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
signSchnorr(r) {
|
|
95
|
-
if (!this.privateKey) throw new Error("Missing private key");
|
|
96
|
-
if (!e.signSchnorr)
|
|
97
|
-
throw new Error("signSchnorr not supported by ecc library");
|
|
98
|
-
return Buffer.from(e.signSchnorr(r, this.privateKey));
|
|
99
|
-
}
|
|
100
|
-
verify(r, t) {
|
|
101
|
-
return e.verify(r, this.publicKey, t);
|
|
102
|
-
}
|
|
103
|
-
verifySchnorr(r, t) {
|
|
104
|
-
if (!e.verifySchnorr)
|
|
105
|
-
throw new Error("verifySchnorr not supported by ecc library");
|
|
106
|
-
return e.verifySchnorr(r, this.publicKey.subarray(1, 33), t);
|
|
107
|
-
}
|
|
108
|
-
tweakFromPublicKey(r) {
|
|
109
|
-
const t = D(this.publicKey), i = e.xOnlyPointAddTweak(t, r);
|
|
110
|
-
if (!i || i.xOnlyPubkey === null)
|
|
111
|
-
throw new Error("Cannot tweak public key!");
|
|
112
|
-
const a = Buffer.from([
|
|
113
|
-
i.parity === 0 ? 2 : 3
|
|
114
|
-
]);
|
|
115
|
-
return h(
|
|
116
|
-
Buffer.concat([a, i.xOnlyPubkey]),
|
|
117
|
-
{ network: this.network, compressed: this.compressed }
|
|
118
|
-
);
|
|
119
|
-
}
|
|
120
|
-
tweakFromPrivateKey(r) {
|
|
121
|
-
const i = this.publicKey[0] === 3 || this.publicKey[0] === 4 && (this.publicKey[64] & 1) === 1 ? e.privateNegate(this.privateKey) : this.privateKey, a = e.privateAdd(i, r);
|
|
122
|
-
if (!a) throw new Error("Invalid tweaked private key!");
|
|
123
|
-
return f(Buffer.from(a), {
|
|
124
|
-
network: this.network,
|
|
125
|
-
compressed: this.compressed
|
|
126
|
-
});
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
return {
|
|
130
|
-
isPoint: n,
|
|
131
|
-
fromPrivateKey: f,
|
|
132
|
-
fromPublicKey: h,
|
|
133
|
-
fromWIF: l,
|
|
134
|
-
makeRandom: _
|
|
135
|
-
};
|
|
136
|
-
}
|
|
137
|
-
p.ECPairFactory = F;
|
|
138
|
-
export {
|
|
139
|
-
p as default
|
|
140
|
-
};
|
package/dist/index23.cjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var e={};exports.__exports=e;
|