@avalabs/bitcoin-module
Advanced tools
Comparing version 0.0.0-feat-btc-get-network-fee-20240717191840 to 0.0.0-feat-btc-get-network-fee-20240718112741
# @avalabs/bitcoin-module | ||
## 0.0.0-feat-btc-get-network-fee-20240717191840 | ||
## 0.0.0-feat-btc-get-network-fee-20240718112741 | ||
@@ -8,2 +8,2 @@ ### Patch Changes | ||
- de9824c: feat: created bitcoin module | ||
- @avalabs/vm-module-types@0.0.0-feat-btc-get-network-fee-20240717191840 | ||
- @avalabs/vm-module-types@0.0.0-feat-btc-get-network-fee-20240718112741 |
@@ -10,3 +10,3 @@ import * as _metamask_rpc_errors from '@metamask/rpc-errors'; | ||
getAddress(): Promise<string>; | ||
getBalances(): Promise<string>; | ||
getBalances(): Promise<{}>; | ||
getManifest(): Manifest | undefined; | ||
@@ -13,0 +13,0 @@ getNetworkFee(network: Network): Promise<NetworkFees>; |
@@ -5,6 +5,6 @@ import { parseManifest, Environment } from '@avalabs/vm-module-types'; | ||
var n=(r,e,t)=>{if(!e.has(r))throw TypeError("Cannot "+t)};var i=(r,e,t)=>(n(r,e,"read from private field"),t?t.call(r):e.get(r)),a=(r,e,t)=>{if(e.has(r))throw TypeError("Cannot add the same private member more than once");e instanceof WeakSet?e.add(r):e.set(r,t);},p=(r,e,t,s)=>(n(r,e,"write to private field"),s?s.call(r,t):e.set(r,t),t);var f={glacierApiUrl:"https://glacier-api.avax.network",proxyApiUrl:"https://proxy-api.avax.network"},k={glacierApiUrl:"https://glacier-api-dev.avax.network",proxyApiUrl:"https://proxy-api-dev.avax.network"},c=r=>{switch(r){case Environment.PRODUCTION:return f;case Environment.DEV:return k}};var d={name:"Bitcoin",description:"",version:"0.0.1",sources:{module:{checksum:"",location:{npm:{filePath:"dist/bundle.js",packageName:"@avalabs/bitcoin-module",registry:"https://registry.npmjs.org"}}},provider:{checksum:"",location:{npm:{filePath:"dist/provider.js",packageName:"@avalabs/bitcoin-module",registry:"https://registry.npmjs.org"}}}},network:{chainIds:["bip122:000000000019d6689c085ae165831e93","bip122:000000000933ea01ad0ee984209779ba"],namespaces:["bip122"]},cointype:"60",permissions:{rpc:{dapps:!0,methods:["bitcoin_sendTransaction"]}},manifestVersion:"0.0"};var l=process.env.GLACIER_API_KEY,v=({isTestnet:r,proxyApiUrl:e})=>new BitcoinProvider(!r,void 0,`${e}/proxy/nownodes/${r?"btcbook-testnet":"btcbook"}`,`${e}/proxy/nownodes/${r?"btc-testnet":"btc"}`,l?{token:l}:{});async function g({isTestnet:r,proxyApiUrl:e}){let t=v({isTestnet:r,proxyApiUrl:e}),{high:s,low:y,medium:x}=await t.getFeeRates();return {low:{maxFeePerGas:BigInt(y)},medium:{maxFeePerGas:BigInt(x)},high:{maxFeePerGas:BigInt(s)},isFixedFee:!1}}var o,u=class{constructor({environment:e}){a(this,o,void 0);let{proxyApiUrl:t}=c(e);p(this,o,t);}getAddress(){return Promise.resolve("Bitcoin address")}getBalances(){return Promise.resolve("Bitcoin balances")}getManifest(){let e=parseManifest(d);return e.success?e.data:void 0}getNetworkFee(e){let{isTestnet:t}=e;return g({isTestnet:!!t,proxyApiUrl:i(this,o)})}getTransactionHistory(e){return Promise.resolve({transactions:[]})}getTokens(e){return Promise.resolve([])}async onRpcRequest(e,t){switch(e.method){default:return {error:rpcErrors.methodNotSupported(`Method ${e.method} not supported`)}}}};o=new WeakMap; | ||
var n=(r,e,t)=>{if(!e.has(r))throw TypeError("Cannot "+t)};var i=(r,e,t)=>(n(r,e,"read from private field"),t?t.call(r):e.get(r)),a=(r,e,t)=>{if(e.has(r))throw TypeError("Cannot add the same private member more than once");e instanceof WeakSet?e.add(r):e.set(r,t);},p=(r,e,t,s)=>(n(r,e,"write to private field"),s?s.call(r,t):e.set(r,t),t);var y={glacierApiUrl:"https://glacier-api.avax.network",proxyApiUrl:"https://proxy-api.avax.network"},f={glacierApiUrl:"https://glacier-api-dev.avax.network",proxyApiUrl:"https://proxy-api-dev.avax.network"},c=r=>{switch(r){case Environment.PRODUCTION:return y;case Environment.DEV:return f}};var d={name:"Bitcoin",description:"",version:"0.0.1",sources:{module:{checksum:"",location:{npm:{filePath:"dist/bundle.js",packageName:"@avalabs/bitcoin-module",registry:"https://registry.npmjs.org"}}},provider:{checksum:"",location:{npm:{filePath:"dist/provider.js",packageName:"@avalabs/bitcoin-module",registry:"https://registry.npmjs.org"}}}},network:{chainIds:["bip122:000000000019d6689c085ae165831e93","bip122:000000000933ea01ad0ee984209779ba"],namespaces:["bip122"]},cointype:"60",permissions:{rpc:{dapps:!0,methods:["bitcoin_sendTransaction"]}},manifestVersion:"0.0"};var l=({isTestnet:r,proxyApiUrl:e})=>new BitcoinProvider(!r,void 0,`${e}/proxy/nownodes/${r?"btcbook-testnet":"btcbook"}`,`${e}/proxy/nownodes/${r?"btc-testnet":"btc"}`,process.env.GLACIER_API_KEY?{token:process.env.GLACIER_API_KEY}:{});async function v({isTestnet:r,proxyApiUrl:e}){let t=l({isTestnet:r,proxyApiUrl:e}),{high:s,low:u,medium:x}=await t.getFeeRates();return {low:{maxFeePerGas:BigInt(u)},medium:{maxFeePerGas:BigInt(x)},high:{maxFeePerGas:BigInt(s)},isFixedFee:!1}}var o,g=class{constructor({environment:e}){a(this,o,void 0);let{proxyApiUrl:t}=c(e);p(this,o,t);}getAddress(){return Promise.resolve("Bitcoin address")}getBalances(){return Promise.resolve({})}getManifest(){let e=parseManifest(d);return e.success?e.data:void 0}getNetworkFee(e){return v({isTestnet:!!e.isTestnet,proxyApiUrl:i(this,o)})}getTransactionHistory(e){return Promise.resolve({transactions:[]})}getTokens(e){return Promise.resolve([])}async onRpcRequest(e,t){switch(e.method){default:return {error:rpcErrors.methodNotSupported(`Method ${e.method} not supported`)}}}};o=new WeakMap; | ||
export { u as BitcoinModule }; | ||
export { g as BitcoinModule }; | ||
//# sourceMappingURL=out.js.map | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@avalabs/bitcoin-module", | ||
"version": "0.0.0-feat-btc-get-network-fee-20240717191840", | ||
"version": "0.0.0-feat-btc-get-network-fee-20240718112741", | ||
"main": "dist/index.cjs", | ||
@@ -9,3 +9,3 @@ "module": "dist/index.js", | ||
"dependencies": { | ||
"@avalabs/vm-module-types": "0.0.0-feat-btc-get-network-fee-20240717191840", | ||
"@avalabs/vm-module-types": "0.0.0-feat-btc-get-network-fee-20240718112741", | ||
"@avalabs/wallets-sdk": "2.8.0-alpha.188", | ||
@@ -20,3 +20,3 @@ "@metamask/rpc-errors": "6.3.0" | ||
"@internal/tsup-config": "0.0.1", | ||
"@internal/utils": "0.0.0-feat-btc-get-network-fee-20240717191840", | ||
"@internal/utils": "0.0.0-feat-btc-get-network-fee-20240718112741", | ||
"eslint-config-custom": "0.0.1" | ||
@@ -23,0 +23,0 @@ }, |
@@ -15,3 +15,3 @@ import type { | ||
import ManifestJson from '../manifest.json'; | ||
import { getNetworkFee } from './handlers/get-network-fee/get-network-fee'; | ||
import { getNetworkFee } from './handlers/get-network-fee'; | ||
@@ -31,3 +31,3 @@ export class BitcoinModule implements Module { | ||
getBalances() { | ||
return Promise.resolve('Bitcoin balances'); | ||
return Promise.resolve({}); | ||
} | ||
@@ -41,6 +41,4 @@ | ||
getNetworkFee(network: Network): Promise<NetworkFees> { | ||
const { isTestnet } = network; | ||
return getNetworkFee({ | ||
isTestnet: Boolean(isTestnet), | ||
isTestnet: Boolean(network.isTestnet), | ||
proxyApiUrl: this.#proxyApiUrl, | ||
@@ -47,0 +45,0 @@ }); |
import { BitcoinProvider } from '@avalabs/wallets-sdk'; | ||
// this key is only needed in development to bypass rate limit | ||
// it should never be used in production | ||
const GLACIER_API_KEY = process.env.GLACIER_API_KEY; | ||
type ProviderParams = { | ||
@@ -18,3 +14,6 @@ isTestnet: boolean; | ||
`${proxyApiUrl}/proxy/nownodes/${isTestnet ? 'btc-testnet' : 'btc'}`, | ||
GLACIER_API_KEY ? { token: GLACIER_API_KEY } : {}, | ||
// The Glacier API key is only needed in development to bypass rate limits. | ||
// It should never be used in production. | ||
process.env.GLACIER_API_KEY ? { token: process.env.GLACIER_API_KEY } : {}, | ||
); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
32356
25
339
44
13
5
373
19
373