Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@stacks/network

Package Overview
Dependencies
Maintainers
0
Versions
630
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@stacks/network - npm Package Compare versions

Comparing version 7.0.0-next.70 to 7.0.0-next.89

17

dist/esm/network.d.ts

@@ -1,3 +0,4 @@

import { ClientOpts } from '@stacks/common';
export interface StacksNetwork {
import { ClientOpts, FetchFn } from '@stacks/common';
import { ClientParam } from '@stacks/common';
export type StacksNetwork = {
chainId: number;

@@ -12,3 +13,11 @@ transactionVersion: number;

};
client: {
baseUrl: string;
fetch?: FetchFn;
};
};
export interface NetworkParam {
network?: StacksNetworkName | StacksNetwork;
}
export type NetworkClientParam = NetworkParam & ClientParam;
export declare const STACKS_MAINNET: StacksNetwork;

@@ -22,3 +31,3 @@ export declare const STACKS_TESTNET: StacksNetwork;

export declare function networkFrom(network: StacksNetworkName | StacksNetwork): StacksNetwork;
export declare function defaultUrlFromNetwork(network?: StacksNetwork | StacksNetworkName): "https://api.mainnet.hiro.so" | "http://localhost:3999" | "https://api.testnet.hiro.so";
export declare const defaultClientOptsFromNetwork: (network?: StacksNetworkName | StacksNetwork, override?: ClientOpts) => Required<ClientOpts>;
export declare function defaultUrlFromNetwork(network?: StacksNetworkName | StacksNetwork): "https://api.mainnet.hiro.so" | "https://api.testnet.hiro.so" | "http://localhost:3999";
export declare function clientFromNetwork(network: StacksNetwork): Required<ClientOpts>;

@@ -13,2 +13,3 @@ import { DEVNET_URL, HIRO_MAINNET_URL, HIRO_TESTNET_URL, createFetchFn, } from '@stacks/common';

},
client: { baseUrl: HIRO_MAINNET_URL },
};

@@ -25,8 +26,15 @@ export const STACKS_TESTNET = {

},
client: { baseUrl: HIRO_TESTNET_URL },
};
export const STACKS_DEVNET = {
...STACKS_TESTNET,
addressVersion: { ...STACKS_TESTNET.addressVersion },
magicBytes: 'id',
client: { baseUrl: DEVNET_URL },
};
export const STACKS_MOCKNET = { ...STACKS_DEVNET };
export const STACKS_MOCKNET = {
...STACKS_DEVNET,
addressVersion: { ...STACKS_DEVNET.addressVersion },
client: { ...STACKS_DEVNET.client },
};
export const StacksNetworks = ['mainnet', 'testnet', 'devnet', 'mocknet'];

@@ -62,8 +70,10 @@ export function networkFromName(name) {

}
export const defaultClientOptsFromNetwork = (network, override) => {
return Object.assign({}, {
baseUrl: defaultUrlFromNetwork(network),
export function clientFromNetwork(network) {
if (network.client.fetch)
return network.client;
return {
...network.client,
fetch: createFetchFn(),
}, override);
};
};
}
//# sourceMappingURL=network.js.map

@@ -1,3 +0,4 @@

import { ClientOpts } from '@stacks/common';
export interface StacksNetwork {
import { ClientOpts, FetchFn } from '@stacks/common';
import { ClientParam } from '@stacks/common';
export type StacksNetwork = {
chainId: number;

@@ -12,3 +13,11 @@ transactionVersion: number;

};
client: {
baseUrl: string;
fetch?: FetchFn;
};
};
export interface NetworkParam {
network?: StacksNetworkName | StacksNetwork;
}
export type NetworkClientParam = NetworkParam & ClientParam;
export declare const STACKS_MAINNET: StacksNetwork;

@@ -22,3 +31,3 @@ export declare const STACKS_TESTNET: StacksNetwork;

export declare function networkFrom(network: StacksNetworkName | StacksNetwork): StacksNetwork;
export declare function defaultUrlFromNetwork(network?: StacksNetwork | StacksNetworkName): "https://api.mainnet.hiro.so" | "http://localhost:3999" | "https://api.testnet.hiro.so";
export declare const defaultClientOptsFromNetwork: (network?: StacksNetworkName | StacksNetwork, override?: ClientOpts) => Required<ClientOpts>;
export declare function defaultUrlFromNetwork(network?: StacksNetworkName | StacksNetwork): "https://api.mainnet.hiro.so" | "https://api.testnet.hiro.so" | "http://localhost:3999";
export declare function clientFromNetwork(network: StacksNetwork): Required<ClientOpts>;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.defaultClientOptsFromNetwork = exports.defaultUrlFromNetwork = exports.networkFrom = exports.networkFromName = exports.StacksNetworks = exports.STACKS_MOCKNET = exports.STACKS_DEVNET = exports.STACKS_TESTNET = exports.STACKS_MAINNET = void 0;
exports.clientFromNetwork = exports.defaultUrlFromNetwork = exports.networkFrom = exports.networkFromName = exports.StacksNetworks = exports.STACKS_MOCKNET = exports.STACKS_DEVNET = exports.STACKS_TESTNET = exports.STACKS_MAINNET = void 0;
const common_1 = require("@stacks/common");

@@ -16,2 +16,3 @@ const constants_1 = require("./constants");

},
client: { baseUrl: common_1.HIRO_MAINNET_URL },
};

@@ -28,8 +29,15 @@ exports.STACKS_TESTNET = {

},
client: { baseUrl: common_1.HIRO_TESTNET_URL },
};
exports.STACKS_DEVNET = {
...exports.STACKS_TESTNET,
addressVersion: { ...exports.STACKS_TESTNET.addressVersion },
magicBytes: 'id',
client: { baseUrl: common_1.DEVNET_URL },
};
exports.STACKS_MOCKNET = { ...exports.STACKS_DEVNET };
exports.STACKS_MOCKNET = {
...exports.STACKS_DEVNET,
addressVersion: { ...exports.STACKS_DEVNET.addressVersion },
client: { ...exports.STACKS_DEVNET.client },
};
exports.StacksNetworks = ['mainnet', 'testnet', 'devnet', 'mocknet'];

@@ -68,9 +76,11 @@ function networkFromName(name) {

exports.defaultUrlFromNetwork = defaultUrlFromNetwork;
const defaultClientOptsFromNetwork = (network, override) => {
return Object.assign({}, {
baseUrl: defaultUrlFromNetwork(network),
function clientFromNetwork(network) {
if (network.client.fetch)
return network.client;
return {
...network.client,
fetch: (0, common_1.createFetchFn)(),
}, override);
};
exports.defaultClientOptsFromNetwork = defaultClientOptsFromNetwork;
};
}
exports.clientFromNetwork = clientFromNetwork;
//# sourceMappingURL=network.js.map

@@ -1,2 +0,2 @@

!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.StacksNetwork=t():e.StacksNetwork=t()}(this,(()=>(()=>{"use strict";var e={d:(t,n)=>{for(var r in n)e.o(n,r)&&!e.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:n[r]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};e.r(t),e.d(t,{AddressVersion:()=>s,ChainId:()=>n,DEFAULT_CHAIN_ID:()=>i,DEFAULT_TRANSACTION_VERSION:()=>a,PeerNetworkId:()=>r,STACKS_DEVNET:()=>N,STACKS_MAINNET:()=>O,STACKS_MOCKNET:()=>j,STACKS_TESTNET:()=>k,StacksNetworks:()=>v,TransactionVersion:()=>o,defaultClientOptsFromNetwork:()=>E,defaultUrlFromNetwork:()=>I,networkFrom:()=>P,networkFromName:()=>A,whenTransactionVersion:()=>c});var n=(e=>(e[e.Mainnet=1]="Mainnet",e[e.Testnet=2147483648]="Testnet",e))(n||{}),r=(e=>(e[e.Mainnet=385875968]="Mainnet",e[e.Testnet=4278190080]="Testnet",e))(r||{});const i=1;var o=(e=>(e[e.Mainnet=0]="Mainnet",e[e.Testnet=128]="Testnet",e))(o||{}),s=(e=>(e[e.MainnetSingleSig=22]="MainnetSingleSig",e[e.MainnetMultiSig=20]="MainnetMultiSig",e[e.TestnetSingleSig=26]="TestnetSingleSig",e[e.TestnetMultiSig=21]="TestnetMultiSig",e))(s||{});const a=0;function c(e){return t=>t[e]}const l="https://api.mainnet.hiro.so",u="https://api.testnet.hiro.so",f="http://localhost:3999",d={referrerPolicy:"origin",headers:{"x-hiro-product":"stacksjs"}};async function p(e,t){const n={};return Object.assign(n,d,t),await fetch(e,n)}function S(...e){const{fetchLib:t,middlewares:n}=function(e){let t=p,n=[];return e.length>0&&"function"==typeof e[0]&&(t=e.shift()),e.length>0&&(n=e),{fetchLib:t,middlewares:n}}(e);return async(e,r)=>{let i={url:e,init:r??{}};for(const e of n)"function"==typeof e.pre&&(i=await Promise.resolve(e.pre({fetch:t,...i}))??i);let o=await t(i.url,i.init);for(const e of n)if("function"==typeof e.post){const n=await Promise.resolve(e.post({fetch:t,url:i.url,init:i.init,response:o?.clone()??o}));o=n??o}return o}}var g=Object.defineProperty,T=Object.defineProperties,y=Object.getOwnPropertyDescriptors,m=Object.getOwnPropertySymbols,b=Object.prototype.hasOwnProperty,w=Object.prototype.propertyIsEnumerable,M=(e,t,n)=>t in e?g(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,h=(e,t)=>{for(var n in t||(t={}))b.call(t,n)&&M(e,n,t[n]);if(m)for(var n of m(t))w.call(t,n)&&M(e,n,t[n]);return e};const O={chainId:n.Mainnet,transactionVersion:o.Mainnet,peerNetworkId:r.Mainnet,magicBytes:"X2",bootAddress:"SP000000000000000000002Q6VF78",addressVersion:{singleSig:s.MainnetSingleSig,multiSig:s.MainnetMultiSig}},k={chainId:n.Testnet,transactionVersion:o.Testnet,peerNetworkId:r.Testnet,magicBytes:"T2",bootAddress:"ST000000000000000000002AMW42H",addressVersion:{singleSig:s.TestnetSingleSig,multiSig:s.TestnetMultiSig}},N=T(h({},k),y({magicBytes:"id"}));const j=h({},N),v=["mainnet","testnet","devnet","mocknet"];function A(e){switch(e){case"mainnet":return O;case"testnet":return k;case"devnet":return N;case"mocknet":return j;default:throw new Error(`Unknown network name: ${e}`)}}function P(e){return"string"==typeof e?A(e):e}function I(e){return e&&(e=P(e))&&e.transactionVersion!==o.Mainnet?"id"===e.magicBytes?f:u:l}const E=(e,t)=>Object.assign({},{baseUrl:I(e),fetch:S()},t);return t})()));
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.StacksNetwork=t():e.StacksNetwork=t()}(this,(()=>(()=>{"use strict";var e={d:(t,n)=>{for(var r in n)e.o(n,r)&&!e.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:n[r]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};e.r(t),e.d(t,{AddressVersion:()=>s,ChainId:()=>n,DEFAULT_CHAIN_ID:()=>i,DEFAULT_TRANSACTION_VERSION:()=>a,PeerNetworkId:()=>r,STACKS_DEVNET:()=>j,STACKS_MAINNET:()=>N,STACKS_MOCKNET:()=>V,STACKS_TESTNET:()=>O,StacksNetworks:()=>v,TransactionVersion:()=>o,clientFromNetwork:()=>E,defaultUrlFromNetwork:()=>I,networkFrom:()=>P,networkFromName:()=>A,whenTransactionVersion:()=>c});var n=(e=>(e[e.Mainnet=1]="Mainnet",e[e.Testnet=2147483648]="Testnet",e))(n||{}),r=(e=>(e[e.Mainnet=385875968]="Mainnet",e[e.Testnet=4278190080]="Testnet",e))(r||{});const i=1;var o=(e=>(e[e.Mainnet=0]="Mainnet",e[e.Testnet=128]="Testnet",e))(o||{}),s=(e=>(e[e.MainnetSingleSig=22]="MainnetSingleSig",e[e.MainnetMultiSig=20]="MainnetMultiSig",e[e.TestnetSingleSig=26]="TestnetSingleSig",e[e.TestnetMultiSig=21]="TestnetMultiSig",e))(s||{});const a=0;function c(e){return t=>t[e]}const l="https://api.mainnet.hiro.so",u="https://api.testnet.hiro.so",d="http://localhost:3999",f={referrerPolicy:"origin",headers:{"x-hiro-product":"stacksjs"}};async function p(e,t){const n={};return Object.assign(n,f,t),await fetch(e,n)}function S(...e){const{fetchLib:t,middlewares:n}=function(e){let t=p,n=[];return e.length>0&&"function"==typeof e[0]&&(t=e.shift()),e.length>0&&(n=e),{fetchLib:t,middlewares:n}}(e);return async(e,r)=>{let i={url:e,init:r??{}};for(const e of n)"function"==typeof e.pre&&(i=await Promise.resolve(e.pre({fetch:t,...i}))??i);let o=await t(i.url,i.init);for(const e of n)if("function"==typeof e.post){const n=await Promise.resolve(e.post({fetch:t,url:i.url,init:i.init,response:o?.clone()??o}));o=n??o}return o}}var g=Object.defineProperty,T=Object.defineProperties,y=Object.getOwnPropertyDescriptors,m=Object.getOwnPropertySymbols,b=Object.prototype.hasOwnProperty,h=Object.prototype.propertyIsEnumerable,w=(e,t,n)=>t in e?g(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,M=(e,t)=>{for(var n in t||(t={}))b.call(t,n)&&w(e,n,t[n]);if(m)for(var n of m(t))h.call(t,n)&&w(e,n,t[n]);return e},k=(e,t)=>T(e,y(t));const N={chainId:n.Mainnet,transactionVersion:o.Mainnet,peerNetworkId:r.Mainnet,magicBytes:"X2",bootAddress:"SP000000000000000000002Q6VF78",addressVersion:{singleSig:s.MainnetSingleSig,multiSig:s.MainnetMultiSig},client:{baseUrl:l}},O={chainId:n.Testnet,transactionVersion:o.Testnet,peerNetworkId:r.Testnet,magicBytes:"T2",bootAddress:"ST000000000000000000002AMW42H",addressVersion:{singleSig:s.TestnetSingleSig,multiSig:s.TestnetMultiSig},client:{baseUrl:u}},j=k(M({},O),{addressVersion:M({},O.addressVersion),magicBytes:"id",client:{baseUrl:d}}),V=k(M({},j),{addressVersion:M({},j.addressVersion),client:M({},j.client)}),v=["mainnet","testnet","devnet","mocknet"];function A(e){switch(e){case"mainnet":return N;case"testnet":return O;case"devnet":return j;case"mocknet":return V;default:throw new Error(`Unknown network name: ${e}`)}}function P(e){return"string"==typeof e?A(e):e}function I(e){return e&&(e=P(e))&&e.transactionVersion!==o.Mainnet?"id"===e.magicBytes?d:u:l}function E(e){return e.client.fetch?e.client:k(M({},e.client),{fetch:S()})}return t})()));
//# sourceMappingURL=index.js.map
{
"name": "@stacks/network",
"version": "7.0.0-next.70+0adf46c4",
"version": "7.0.0-next.89+3d4052b2",
"description": "Library for Stacks network operations",

@@ -23,3 +23,3 @@ "license": "MIT",

"dependencies": {
"@stacks/common": "^7.0.0-next.70+0adf46c4",
"@stacks/common": "^7.0.0-next.89+3d4052b2",
"cross-fetch": "^3.1.5"

@@ -56,3 +56,3 @@ },

},
"gitHead": "0adf46c4eadac85f234140dc2df0e5d06b0ca775"
"gitHead": "3d4052b21c76cd8f28ae64a266d61b650386a726"
}
import {
ClientOpts,
DEVNET_URL,
FetchFn,
HIRO_MAINNET_URL,

@@ -9,4 +10,5 @@ HIRO_TESTNET_URL,

import { AddressVersion, ChainId, PeerNetworkId, TransactionVersion } from './constants';
import { ClientParam } from '@stacks/common';
export interface StacksNetwork {
export type StacksNetwork = {
chainId: number;

@@ -22,4 +24,14 @@ transactionVersion: number; // todo: txVersion better?

// todo: add check32 character bytes string
client: {
baseUrl: string; // URL is always required
fetch?: FetchFn; // fetch is optional and will be created by default in fetch helpers
};
};
export interface NetworkParam {
network?: StacksNetworkName | StacksNetwork;
}
export type NetworkClientParam = NetworkParam & ClientParam;
export const STACKS_MAINNET: StacksNetwork = {

@@ -35,2 +47,3 @@ chainId: ChainId.Mainnet,

},
client: { baseUrl: HIRO_MAINNET_URL },
};

@@ -48,10 +61,18 @@

},
client: { baseUrl: HIRO_TESTNET_URL },
};
export const STACKS_DEVNET: StacksNetwork = {
...STACKS_TESTNET,
...STACKS_TESTNET, // todo: ensure deep copy
addressVersion: { ...STACKS_TESTNET.addressVersion }, // deep copy
magicBytes: 'id', // todo: comment bytes version of magic bytes
client: { baseUrl: DEVNET_URL },
};
export const STACKS_MOCKNET: StacksNetwork = { ...STACKS_DEVNET };
export const STACKS_MOCKNET: StacksNetwork = {
...STACKS_DEVNET,
addressVersion: { ...STACKS_DEVNET.addressVersion }, // deep copy
client: { ...STACKS_DEVNET.client }, // deep copy
};
/** @ignore internal */

@@ -62,2 +83,12 @@ export const StacksNetworks = ['mainnet', 'testnet', 'devnet', 'mocknet'] as const;

/**
* Returns the default network for a given name
* @example
* ```ts
* networkFromName('mainnet') // same as STACKS_MAINNET
* networkFromName('testnet') // same as STACKS_TESTNET
* networkFromName('devnet') // same as STACKS_DEVNET
* networkFromName('mocknet') // same as STACKS_MOCKNET
* ```
*/
export function networkFromName(name: StacksNetworkName) {

@@ -85,3 +116,3 @@ switch (name) {

/** @ignore */
export function defaultUrlFromNetwork(network?: StacksNetwork | StacksNetworkName) {
export function defaultUrlFromNetwork(network?: StacksNetworkName | StacksNetwork) {
if (!network) return HIRO_MAINNET_URL; // default to mainnet if no network is given

@@ -98,15 +129,11 @@

/** @ignore */
export const defaultClientOptsFromNetwork = (
network?: StacksNetworkName | StacksNetwork,
override?: ClientOpts
): Required<ClientOpts> => {
return Object.assign(
{},
{
baseUrl: defaultUrlFromNetwork(network),
fetch: createFetchFn(),
},
override
);
};
/**
* Returns the client of a network, creating a new fetch function if none is available
*/
export function clientFromNetwork(network: StacksNetwork): Required<ClientOpts> {
if (network.client.fetch) return network.client as Required<ClientOpts>;
return {
...network.client,
fetch: createFetchFn(),
};
}

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc