@stacks/network 4.0.2-beta.1 → 4.1.0

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/fetch.js ADDED
@@ -0,0 +1,81 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createFetchFn = exports.createApiKeyMiddleware = exports.hostMatches = exports.fetchWrapper = exports.setFetchOptions = exports.getFetchOptions = void 0;
4
+ require("cross-fetch/polyfill");
5
+ const defaultFetchOpts = {
6
+ referrerPolicy: 'origin',
7
+ };
8
+ const getFetchOptions = () => {
9
+ return defaultFetchOpts;
10
+ };
11
+ exports.getFetchOptions = getFetchOptions;
12
+ const setFetchOptions = (ops) => {
13
+ return Object.assign(defaultFetchOpts, ops);
14
+ };
15
+ exports.setFetchOptions = setFetchOptions;
16
+ async function fetchWrapper(input, init) {
17
+ const fetchOpts = {};
18
+ Object.assign(fetchOpts, init, defaultFetchOpts);
19
+ const fetchResult = await fetch(input, fetchOpts);
20
+ return fetchResult;
21
+ }
22
+ exports.fetchWrapper = fetchWrapper;
23
+ function hostMatches(host, pattern) {
24
+ if (typeof pattern === 'string')
25
+ return pattern === host;
26
+ return pattern.exec(host);
27
+ }
28
+ exports.hostMatches = hostMatches;
29
+ function createApiKeyMiddleware({ apiKey, host = /(.*)api(.*)\.stacks\.co$/i, httpHeader = 'x-api-key', }) {
30
+ return {
31
+ pre: context => {
32
+ const reqUrl = new URL(context.url);
33
+ if (!hostMatches(reqUrl.host, host))
34
+ return;
35
+ const headers = new Headers(context.init.headers);
36
+ headers.set(httpHeader, apiKey);
37
+ context.init.headers = headers;
38
+ },
39
+ };
40
+ }
41
+ exports.createApiKeyMiddleware = createApiKeyMiddleware;
42
+ function argsForCreateFetchFn(args) {
43
+ let fetchLib = fetchWrapper;
44
+ let middlewares = [];
45
+ if (args.length > 0 && typeof args[0] === 'function') {
46
+ fetchLib = args.shift();
47
+ }
48
+ if (args.length > 0) {
49
+ middlewares = args;
50
+ }
51
+ return { fetchLib, middlewares };
52
+ }
53
+ function createFetchFn(...args) {
54
+ const { fetchLib, middlewares } = argsForCreateFetchFn(args);
55
+ const fetchFn = async (url, init) => {
56
+ var _a;
57
+ let fetchParams = { url, init: init !== null && init !== void 0 ? init : {} };
58
+ for (const middleware of middlewares) {
59
+ if (typeof middleware.pre === 'function') {
60
+ const result = await Promise.resolve(middleware.pre(Object.assign({ fetch: fetchLib }, fetchParams)));
61
+ fetchParams = result !== null && result !== void 0 ? result : fetchParams;
62
+ }
63
+ }
64
+ let response = await fetchLib(fetchParams.url, fetchParams.init);
65
+ for (const middleware of middlewares) {
66
+ if (typeof middleware.post === 'function') {
67
+ const result = await Promise.resolve(middleware.post({
68
+ fetch: fetchLib,
69
+ url: fetchParams.url,
70
+ init: fetchParams.init,
71
+ response: (_a = response === null || response === void 0 ? void 0 : response.clone()) !== null && _a !== void 0 ? _a : response,
72
+ }));
73
+ response = result !== null && result !== void 0 ? result : response;
74
+ }
75
+ }
76
+ return response;
77
+ };
78
+ return fetchFn;
79
+ }
80
+ exports.createFetchFn = createFetchFn;
81
+ //# sourceMappingURL=fetch.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fetch.js","sourceRoot":"","sources":["../src/fetch.ts"],"names":[],"mappings":";;;AAAA,gCAA8B;AAI9B,MAAM,gBAAgB,GAAgB;IAEpC,cAAc,EAAE,QAAQ;CAEzB,CAAC;AAMK,MAAM,eAAe,GAAG,GAAG,EAAE;IAClC,OAAO,gBAAgB,CAAC;AAC1B,CAAC,CAAC;AAFW,QAAA,eAAe,mBAE1B;AAiBK,MAAM,eAAe,GAAG,CAAC,GAAgB,EAAe,EAAE;IAC/D,OAAO,MAAM,CAAC,MAAM,CAAC,gBAAgB,EAAE,GAAG,CAAC,CAAC;AAC9C,CAAC,CAAC;AAFW,QAAA,eAAe,mBAE1B;AAGK,KAAK,UAAU,YAAY,CAAC,KAAkB,EAAE,IAAkB;IACvE,MAAM,SAAS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,GAAG,MAAM,aAAN,MAAM,cAAN,MAAM,GAAI,QAAQ,CAAC;aAC/B;SACF;QACD,OAAO,QAAQ,CAAC;IAClB,CAAC,CAAC;IACF,OAAO,OAAO,CAAC;AACjB,CAAC;AApCD,sCAoCC"}
package/dist/index.d.ts CHANGED
@@ -1,54 +1,2 @@
1
- import { TransactionVersion, ChainID } from '@stacks/common';
2
- export declare const HIRO_MAINNET_DEFAULT = "https://stacks-node-api.mainnet.stacks.co";
3
- export declare const HIRO_TESTNET_DEFAULT = "https://stacks-node-api.testnet.stacks.co";
4
- export declare const HIRO_MOCKNET_DEFAULT = "http://localhost:3999";
5
- export interface NetworkConfig {
6
- url: string;
7
- }
8
- export declare const StacksNetworks: readonly ["mainnet", "testnet"];
9
- export declare type StacksNetworkName = typeof StacksNetworks[number];
10
- export declare class StacksNetwork {
11
- version: TransactionVersion;
12
- chainId: ChainID;
13
- bnsLookupUrl: string;
14
- broadcastEndpoint: string;
15
- transferFeeEstimateEndpoint: string;
16
- transactionFeeEstimateEndpoint: string;
17
- accountEndpoint: string;
18
- contractAbiEndpoint: string;
19
- readOnlyFunctionCallEndpoint: string;
20
- readonly coreApiUrl: string;
21
- constructor(networkConfig: NetworkConfig);
22
- static fromName: (networkName: StacksNetworkName) => StacksNetwork;
23
- static fromNameOrNetwork: (network: StacksNetworkName | StacksNetwork) => StacksNetwork;
24
- isMainnet: () => boolean;
25
- getBroadcastApiUrl: () => string;
26
- getTransferFeeEstimateApiUrl: () => string;
27
- getTransactionFeeEstimateApiUrl: () => string;
28
- getAccountApiUrl: (address: string) => string;
29
- getAbiApiUrl: (address: string, contract: string) => string;
30
- getReadOnlyFunctionCallApiUrl: (contractAddress: string, contractName: string, functionName: string) => string;
31
- getInfoUrl: () => string;
32
- getBlockTimeInfoUrl: () => string;
33
- getPoxInfoUrl: () => string;
34
- getRewardsUrl: (address: string, options?: any) => string;
35
- getRewardsTotalUrl: (address: string) => string;
36
- getRewardHoldersUrl: (address: string, options?: any) => string;
37
- getStackerInfoUrl: (contractAddress: string, contractName: string) => string;
38
- getNameInfo(fullyQualifiedName: string): Promise<any>;
39
- }
40
- export declare class StacksMainnet extends StacksNetwork {
41
- version: TransactionVersion;
42
- chainId: ChainID;
43
- constructor(networkUrl?: NetworkConfig);
44
- }
45
- export declare class StacksTestnet extends StacksNetwork {
46
- version: TransactionVersion;
47
- chainId: ChainID;
48
- constructor(networkUrl?: NetworkConfig);
49
- }
50
- export declare class StacksMocknet extends StacksNetwork {
51
- version: TransactionVersion;
52
- chainId: ChainID;
53
- constructor(networkUrl?: NetworkConfig);
54
- }
1
+ export * from './fetch';
2
+ export * from './network';
package/dist/index.js CHANGED
@@ -1,114 +1,19 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.StacksMocknet = exports.StacksTestnet = exports.StacksMainnet = exports.StacksNetwork = exports.StacksNetworks = exports.HIRO_MOCKNET_DEFAULT = exports.HIRO_TESTNET_DEFAULT = exports.HIRO_MAINNET_DEFAULT = void 0;
4
- const common_1 = require("@stacks/common");
5
- exports.HIRO_MAINNET_DEFAULT = 'https://stacks-node-api.mainnet.stacks.co';
6
- exports.HIRO_TESTNET_DEFAULT = 'https://stacks-node-api.testnet.stacks.co';
7
- exports.HIRO_MOCKNET_DEFAULT = 'http://localhost:3999';
8
- exports.StacksNetworks = ['mainnet', 'testnet'];
9
- class StacksNetwork {
10
- constructor(networkConfig) {
11
- this.version = common_1.TransactionVersion.Mainnet;
12
- this.chainId = common_1.ChainID.Mainnet;
13
- this.bnsLookupUrl = 'https://stacks-node-api.mainnet.stacks.co';
14
- this.broadcastEndpoint = '/v2/transactions';
15
- this.transferFeeEstimateEndpoint = '/v2/fees/transfer';
16
- this.transactionFeeEstimateEndpoint = '/v2/fees/transaction';
17
- this.accountEndpoint = '/v2/accounts';
18
- this.contractAbiEndpoint = '/v2/contracts/interface';
19
- this.readOnlyFunctionCallEndpoint = '/v2/contracts/call-read';
20
- this.isMainnet = () => this.version === common_1.TransactionVersion.Mainnet;
21
- this.getBroadcastApiUrl = () => `${this.coreApiUrl}${this.broadcastEndpoint}`;
22
- this.getTransferFeeEstimateApiUrl = () => `${this.coreApiUrl}${this.transferFeeEstimateEndpoint}`;
23
- this.getTransactionFeeEstimateApiUrl = () => `${this.coreApiUrl}${this.transactionFeeEstimateEndpoint}`;
24
- this.getAccountApiUrl = (address) => `${this.coreApiUrl}${this.accountEndpoint}/${address}?proof=0`;
25
- this.getAbiApiUrl = (address, contract) => `${this.coreApiUrl}${this.contractAbiEndpoint}/${address}/${contract}`;
26
- this.getReadOnlyFunctionCallApiUrl = (contractAddress, contractName, functionName) => `${this.coreApiUrl}${this.readOnlyFunctionCallEndpoint}/${contractAddress}/${contractName}/${encodeURIComponent(functionName)}`;
27
- this.getInfoUrl = () => `${this.coreApiUrl}/v2/info`;
28
- this.getBlockTimeInfoUrl = () => `${this.coreApiUrl}/extended/v1/info/network_block_times`;
29
- this.getPoxInfoUrl = () => `${this.coreApiUrl}/v2/pox`;
30
- this.getRewardsUrl = (address, options) => {
31
- let url = `${this.coreApiUrl}/extended/v1/burnchain/rewards/${address}`;
32
- if (options) {
33
- url = `${url}?limit=${options.limit}&offset=${options.offset}`;
34
- }
35
- return url;
36
- };
37
- this.getRewardsTotalUrl = (address) => `${this.coreApiUrl}/extended/v1/burnchain/rewards/${address}/total`;
38
- this.getRewardHoldersUrl = (address, options) => {
39
- let url = `${this.coreApiUrl}/extended/v1/burnchain/reward_slot_holders/${address}`;
40
- if (options) {
41
- url = `${url}?limit=${options.limit}&offset=${options.offset}`;
42
- }
43
- return url;
44
- };
45
- this.getStackerInfoUrl = (contractAddress, contractName) => `${this.coreApiUrl}${this.readOnlyFunctionCallEndpoint}
46
- ${contractAddress}/${contractName}/get-stacker-info`;
47
- this.coreApiUrl = networkConfig.url;
48
- }
49
- getNameInfo(fullyQualifiedName) {
50
- const nameLookupURL = `${this.bnsLookupUrl}/v1/names/${fullyQualifiedName}`;
51
- return (0, common_1.fetchPrivate)(nameLookupURL)
52
- .then(resp => {
53
- if (resp.status === 404) {
54
- throw new Error('Name not found');
55
- }
56
- else if (resp.status !== 200) {
57
- throw new Error(`Bad response status: ${resp.status}`);
58
- }
59
- else {
60
- return resp.json();
61
- }
62
- })
63
- .then(nameInfo => {
64
- if (nameInfo.address) {
65
- return Object.assign({}, nameInfo, { address: nameInfo.address });
66
- }
67
- else {
68
- return nameInfo;
69
- }
70
- });
71
- }
72
- }
73
- exports.StacksNetwork = StacksNetwork;
74
- StacksNetwork.fromName = (networkName) => {
75
- switch (networkName) {
76
- case 'mainnet':
77
- return new StacksMainnet();
78
- case 'testnet':
79
- return new StacksTestnet();
80
- default:
81
- throw new Error(`Invalid network name provided. Must be one of the following: ${exports.StacksNetworks.join(', ')}`);
82
- }
83
- };
84
- StacksNetwork.fromNameOrNetwork = (network) => {
85
- if (typeof network !== 'string' && 'version' in network) {
86
- return network;
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
87
7
  }
88
- return StacksNetwork.fromName(network);
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
89
15
  };
90
- class StacksMainnet extends StacksNetwork {
91
- constructor(networkUrl = { url: exports.HIRO_MAINNET_DEFAULT }) {
92
- super(networkUrl);
93
- this.version = common_1.TransactionVersion.Mainnet;
94
- this.chainId = common_1.ChainID.Mainnet;
95
- }
96
- }
97
- exports.StacksMainnet = StacksMainnet;
98
- class StacksTestnet extends StacksNetwork {
99
- constructor(networkUrl = { url: exports.HIRO_TESTNET_DEFAULT }) {
100
- super(networkUrl);
101
- this.version = common_1.TransactionVersion.Testnet;
102
- this.chainId = common_1.ChainID.Testnet;
103
- }
104
- }
105
- exports.StacksTestnet = StacksTestnet;
106
- class StacksMocknet extends StacksNetwork {
107
- constructor(networkUrl = { url: exports.HIRO_MOCKNET_DEFAULT }) {
108
- super(networkUrl);
109
- this.version = common_1.TransactionVersion.Testnet;
110
- this.chainId = common_1.ChainID.Testnet;
111
- }
112
- }
113
- exports.StacksMocknet = StacksMocknet;
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./fetch"), exports);
18
+ __exportStar(require("./network"), exports);
114
19
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,2CAA2E;AAE9D,QAAA,oBAAoB,GAAG,2CAA2C,CAAC;AACnE,QAAA,oBAAoB,GAAG,2CAA2C,CAAC;AACnE,QAAA,oBAAoB,GAAG,uBAAuB,CAAC;AAM/C,QAAA,cAAc,GAAG,CAAC,SAAS,EAAE,SAAS,CAAU,CAAC;AAG9D,MAAa,aAAa;IAaxB,YAAY,aAA4B;QAZxC,YAAO,GAAG,2BAAkB,CAAC,OAAO,CAAC;QACrC,YAAO,GAAG,gBAAO,CAAC,OAAO,CAAC;QAC1B,iBAAY,GAAG,2CAA2C,CAAC;QAC3D,sBAAiB,GAAG,kBAAkB,CAAC;QACvC,gCAA2B,GAAG,mBAAmB,CAAC;QAClD,mCAA8B,GAAG,sBAAsB,CAAC;QACxD,oBAAe,GAAG,cAAc,CAAC;QACjC,wBAAmB,GAAG,yBAAyB,CAAC;QAChD,iCAA4B,GAAG,yBAAyB,CAAC;QA+BzD,cAAS,GAAG,GAAG,EAAE,CAAC,IAAI,CAAC,OAAO,KAAK,2BAAkB,CAAC,OAAO,CAAC;QAC9D,u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,aAAa;IAI9C,YAAY,aAA4B,EAAE,GAAG,EAAE,4BAAoB,EAAE;QACnE,KAAK,CAAC,UAAU,CAAC,CAAC;QAJpB,YAAO,GAAG,2BAAkB,CAAC,OAAO,CAAC;QACrC,YAAO,GAAG,gBAAO,CAAC,OAAO,CAAC;IAI1B,CAAC;CACF;AAPD,sCAOC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0CAAwB;AACxB,4CAA0B"}
@@ -0,0 +1,57 @@
1
+ import { TransactionVersion, ChainID } from '@stacks/common';
2
+ import { FetchFn } from './fetch';
3
+ export declare const HIRO_MAINNET_DEFAULT = "https://stacks-node-api.mainnet.stacks.co";
4
+ export declare const HIRO_TESTNET_DEFAULT = "https://stacks-node-api.testnet.stacks.co";
5
+ export declare const HIRO_MOCKNET_DEFAULT = "http://localhost:3999";
6
+ export interface NetworkConfig {
7
+ url: string;
8
+ fetchFn?: FetchFn;
9
+ }
10
+ export declare const StacksNetworks: readonly ["mainnet", "testnet"];
11
+ export declare type StacksNetworkName = typeof StacksNetworks[number];
12
+ export declare class StacksNetwork {
13
+ version: TransactionVersion;
14
+ chainId: ChainID;
15
+ bnsLookupUrl: string;
16
+ broadcastEndpoint: string;
17
+ transferFeeEstimateEndpoint: string;
18
+ transactionFeeEstimateEndpoint: string;
19
+ accountEndpoint: string;
20
+ contractAbiEndpoint: string;
21
+ readOnlyFunctionCallEndpoint: string;
22
+ readonly coreApiUrl: string;
23
+ fetchFn: FetchFn;
24
+ constructor(networkConfig: NetworkConfig);
25
+ static fromName: (networkName: StacksNetworkName) => StacksNetwork;
26
+ static fromNameOrNetwork: (network: StacksNetworkName | StacksNetwork) => StacksNetwork;
27
+ isMainnet: () => boolean;
28
+ getBroadcastApiUrl: () => string;
29
+ getTransferFeeEstimateApiUrl: () => string;
30
+ getTransactionFeeEstimateApiUrl: () => string;
31
+ getAccountApiUrl: (address: string) => string;
32
+ getAbiApiUrl: (address: string, contract: string) => string;
33
+ getReadOnlyFunctionCallApiUrl: (contractAddress: string, contractName: string, functionName: string) => string;
34
+ getInfoUrl: () => string;
35
+ getBlockTimeInfoUrl: () => string;
36
+ getPoxInfoUrl: () => string;
37
+ getRewardsUrl: (address: string, options?: any) => string;
38
+ getRewardsTotalUrl: (address: string) => string;
39
+ getRewardHoldersUrl: (address: string, options?: any) => string;
40
+ getStackerInfoUrl: (contractAddress: string, contractName: string) => string;
41
+ getNameInfo(fullyQualifiedName: string): Promise<any>;
42
+ }
43
+ export declare class StacksMainnet extends StacksNetwork {
44
+ version: TransactionVersion;
45
+ chainId: ChainID;
46
+ constructor(opts?: Partial<NetworkConfig>);
47
+ }
48
+ export declare class StacksTestnet extends StacksNetwork {
49
+ version: TransactionVersion;
50
+ chainId: ChainID;
51
+ constructor(opts?: Partial<NetworkConfig>);
52
+ }
53
+ export declare class StacksMocknet extends StacksNetwork {
54
+ version: TransactionVersion;
55
+ chainId: ChainID;
56
+ constructor(opts?: Partial<NetworkConfig>);
57
+ }
@@ -0,0 +1,129 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.StacksMocknet = exports.StacksTestnet = exports.StacksMainnet = exports.StacksNetwork = exports.StacksNetworks = exports.HIRO_MOCKNET_DEFAULT = exports.HIRO_TESTNET_DEFAULT = exports.HIRO_MAINNET_DEFAULT = void 0;
4
+ const common_1 = require("@stacks/common");
5
+ const fetch_1 = require("./fetch");
6
+ exports.HIRO_MAINNET_DEFAULT = 'https://stacks-node-api.mainnet.stacks.co';
7
+ exports.HIRO_TESTNET_DEFAULT = 'https://stacks-node-api.testnet.stacks.co';
8
+ exports.HIRO_MOCKNET_DEFAULT = 'http://localhost:3999';
9
+ exports.StacksNetworks = ['mainnet', 'testnet'];
10
+ class StacksNetwork {
11
+ constructor(networkConfig) {
12
+ var _a;
13
+ this.version = common_1.TransactionVersion.Mainnet;
14
+ this.chainId = common_1.ChainID.Mainnet;
15
+ this.bnsLookupUrl = 'https://stacks-node-api.mainnet.stacks.co';
16
+ this.broadcastEndpoint = '/v2/transactions';
17
+ this.transferFeeEstimateEndpoint = '/v2/fees/transfer';
18
+ this.transactionFeeEstimateEndpoint = '/v2/fees/transaction';
19
+ this.accountEndpoint = '/v2/accounts';
20
+ this.contractAbiEndpoint = '/v2/contracts/interface';
21
+ this.readOnlyFunctionCallEndpoint = '/v2/contracts/call-read';
22
+ this.isMainnet = () => this.version === common_1.TransactionVersion.Mainnet;
23
+ this.getBroadcastApiUrl = () => `${this.coreApiUrl}${this.broadcastEndpoint}`;
24
+ this.getTransferFeeEstimateApiUrl = () => `${this.coreApiUrl}${this.transferFeeEstimateEndpoint}`;
25
+ this.getTransactionFeeEstimateApiUrl = () => `${this.coreApiUrl}${this.transactionFeeEstimateEndpoint}`;
26
+ this.getAccountApiUrl = (address) => `${this.coreApiUrl}${this.accountEndpoint}/${address}?proof=0`;
27
+ this.getAbiApiUrl = (address, contract) => `${this.coreApiUrl}${this.contractAbiEndpoint}/${address}/${contract}`;
28
+ this.getReadOnlyFunctionCallApiUrl = (contractAddress, contractName, functionName) => `${this.coreApiUrl}${this.readOnlyFunctionCallEndpoint}/${contractAddress}/${contractName}/${encodeURIComponent(functionName)}`;
29
+ this.getInfoUrl = () => `${this.coreApiUrl}/v2/info`;
30
+ this.getBlockTimeInfoUrl = () => `${this.coreApiUrl}/extended/v1/info/network_block_times`;
31
+ this.getPoxInfoUrl = () => `${this.coreApiUrl}/v2/pox`;
32
+ this.getRewardsUrl = (address, options) => {
33
+ let url = `${this.coreApiUrl}/extended/v1/burnchain/rewards/${address}`;
34
+ if (options) {
35
+ url = `${url}?limit=${options.limit}&offset=${options.offset}`;
36
+ }
37
+ return url;
38
+ };
39
+ this.getRewardsTotalUrl = (address) => `${this.coreApiUrl}/extended/v1/burnchain/rewards/${address}/total`;
40
+ this.getRewardHoldersUrl = (address, options) => {
41
+ let url = `${this.coreApiUrl}/extended/v1/burnchain/reward_slot_holders/${address}`;
42
+ if (options) {
43
+ url = `${url}?limit=${options.limit}&offset=${options.offset}`;
44
+ }
45
+ return url;
46
+ };
47
+ this.getStackerInfoUrl = (contractAddress, contractName) => `${this.coreApiUrl}${this.readOnlyFunctionCallEndpoint}
48
+ ${contractAddress}/${contractName}/get-stacker-info`;
49
+ this.coreApiUrl = networkConfig.url;
50
+ this.fetchFn = (_a = networkConfig.fetchFn) !== null && _a !== void 0 ? _a : (0, fetch_1.createFetchFn)();
51
+ }
52
+ getNameInfo(fullyQualifiedName) {
53
+ const nameLookupURL = `${this.bnsLookupUrl}/v1/names/${fullyQualifiedName}`;
54
+ return this.fetchFn(nameLookupURL)
55
+ .then(resp => {
56
+ if (resp.status === 404) {
57
+ throw new Error('Name not found');
58
+ }
59
+ else if (resp.status !== 200) {
60
+ throw new Error(`Bad response status: ${resp.status}`);
61
+ }
62
+ else {
63
+ return resp.json();
64
+ }
65
+ })
66
+ .then(nameInfo => {
67
+ if (nameInfo.address) {
68
+ return Object.assign({}, nameInfo, { address: nameInfo.address });
69
+ }
70
+ else {
71
+ return nameInfo;
72
+ }
73
+ });
74
+ }
75
+ }
76
+ exports.StacksNetwork = StacksNetwork;
77
+ StacksNetwork.fromName = (networkName) => {
78
+ switch (networkName) {
79
+ case 'mainnet':
80
+ return new StacksMainnet();
81
+ case 'testnet':
82
+ return new StacksTestnet();
83
+ default:
84
+ throw new Error(`Invalid network name provided. Must be one of the following: ${exports.StacksNetworks.join(', ')}`);
85
+ }
86
+ };
87
+ StacksNetwork.fromNameOrNetwork = (network) => {
88
+ if (typeof network !== 'string' && 'version' in network) {
89
+ return network;
90
+ }
91
+ return StacksNetwork.fromName(network);
92
+ };
93
+ class StacksMainnet extends StacksNetwork {
94
+ constructor(opts) {
95
+ var _a;
96
+ super({
97
+ url: (_a = opts === null || opts === void 0 ? void 0 : opts.url) !== null && _a !== void 0 ? _a : exports.HIRO_MAINNET_DEFAULT,
98
+ fetchFn: opts === null || opts === void 0 ? void 0 : opts.fetchFn,
99
+ });
100
+ this.version = common_1.TransactionVersion.Mainnet;
101
+ this.chainId = common_1.ChainID.Mainnet;
102
+ }
103
+ }
104
+ exports.StacksMainnet = StacksMainnet;
105
+ class StacksTestnet extends StacksNetwork {
106
+ constructor(opts) {
107
+ var _a;
108
+ super({
109
+ url: (_a = opts === null || opts === void 0 ? void 0 : opts.url) !== null && _a !== void 0 ? _a : exports.HIRO_TESTNET_DEFAULT,
110
+ fetchFn: opts === null || opts === void 0 ? void 0 : opts.fetchFn,
111
+ });
112
+ this.version = common_1.TransactionVersion.Testnet;
113
+ this.chainId = common_1.ChainID.Testnet;
114
+ }
115
+ }
116
+ exports.StacksTestnet = StacksTestnet;
117
+ class StacksMocknet extends StacksNetwork {
118
+ constructor(opts) {
119
+ var _a;
120
+ super({
121
+ url: (_a = opts === null || opts === void 0 ? void 0 : opts.url) !== null && _a !== void 0 ? _a : exports.HIRO_MOCKNET_DEFAULT,
122
+ fetchFn: opts === null || opts === void 0 ? void 0 : opts.fetchFn,
123
+ });
124
+ this.version = common_1.TransactionVersion.Testnet;
125
+ this.chainId = common_1.ChainID.Testnet;
126
+ }
127
+ }
128
+ exports.StacksMocknet = StacksMocknet;
129
+ //# sourceMappingURL=network.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"network.js","sourceRoot":"","sources":["../src/network.ts"],"names":[],"mappings":";;;AAAA,2CAA6D;AAC7D,mCAAiD;AAEpC,QAAA,oBAAoB,GAAG,2CAA2C,CAAC;AACnE,QAAA,oBAAoB,GAAG,2CAA2C,CAAC;AACnE,QAAA,oBAAoB,GAAG,uBAAuB,CAAC;AAO/C,QAAA,cAAc,GAAG,CAAC,SAAS,EAAE,SAAS,CAAU,CAAC;AAM9D,MAAa,aAAa;IAexB,YAAY,aAA4B;;QAdxC,YAAO,GAAG,2BAAkB,CAAC,OAAO,CAAC;QACrC,YAAO,GAAG,gBAAO,CAAC,OAAO,CAAC;QAC1B,iBAAY,GAAG,2CAA2C,CAAC;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,IAAI,uBAAJ,IAAI,CAAE,GAAG,mCAAI,4BAAoB;YACtC,OAAO,EAAE,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,OAAO;SACvB,CAAC,CAAC;QAPL,YAAO,GAAG,2BAAkB,CAAC,OAAO,CAAC;QACrC,YAAO,GAAG,gBAAO,CAAC,OAAO,CAAC;IAO1B,CAAC;CACF;AAVD,sCAUC;AAKD,MAAa,aAAc,SAAQ,aAAa;IAI9C,YAAY,IAA6B;;QACvC,KAAK,CAAC;YACJ,GAAG,EAAE,MAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,GAAG,mCAAI,4BAAoB;YACtC,OAAO,EAAE,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,OAAO;SACvB,CAAC,CAAC;QAPL,YAAO,GAAG,2BAAkB,CAAC,OAAO,CAAC;QACrC,YAAO,GAAG,gBAAO,CAAC,OAAO,CAAC;IAO1B,CAAC;CACF;AAVD,sCAUC;AAED,MAAa,aAAc,SAAQ,aAAa;IAI9C,YAAY,IAA6B;;QACvC,KAAK,CAAC;YACJ,GAAG,EAAE,MAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,GAAG,mCAAI,4BAAoB;YACtC,OAAO,EAAE,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,OAAO;SACvB,CAAC,CAAC;QAPL,YAAO,GAAG,2BAAkB,CAAC,OAAO,CAAC;QACrC,YAAO,GAAG,gBAAO,CAAC,OAAO,CAAC;IAO1B,CAAC;CACF;AAVD,sCAUC"}
@@ -1 +1 @@
1
- window.global=window;import{TransactionVersion as t,ChainID as s,fetchPrivate as e}from"@stacks/common/dist/polyfill";const n="https://stacks-node-api.mainnet.stacks.co",i="https://stacks-node-api.testnet.stacks.co",r="http://localhost:3999",o=["mainnet","testnet"];class a{constructor(e){this.version=t.Mainnet,this.chainId=s.Mainnet,this.bnsLookupUrl="https://stacks-node-api.mainnet.stacks.co",this.broadcastEndpoint="/v2/transactions",this.transferFeeEstimateEndpoint="/v2/fees/transfer",this.transactionFeeEstimateEndpoint="/v2/fees/transaction",this.accountEndpoint="/v2/accounts",this.contractAbiEndpoint="/v2/contracts/interface",this.readOnlyFunctionCallEndpoint="/v2/contracts/call-read",this.isMainnet=()=>this.version===t.Mainnet,this.getBroadcastApiUrl=()=>`${this.coreApiUrl}${this.broadcastEndpoint}`,this.getTransferFeeEstimateApiUrl=()=>`${this.coreApiUrl}${this.transferFeeEstimateEndpoint}`,this.getTransactionFeeEstimateApiUrl=()=>`${this.coreApiUrl}${this.transactionFeeEstimateEndpoint}`,this.getAccountApiUrl=t=>`${this.coreApiUrl}${this.accountEndpoint}/${t}?proof=0`,this.getAbiApiUrl=(t,s)=>`${this.coreApiUrl}${this.contractAbiEndpoint}/${t}/${s}`,this.getReadOnlyFunctionCallApiUrl=(t,s,e)=>`${this.coreApiUrl}${this.readOnlyFunctionCallEndpoint}/${t}/${s}/${encodeURIComponent(e)}`,this.getInfoUrl=()=>`${this.coreApiUrl}/v2/info`,this.getBlockTimeInfoUrl=()=>`${this.coreApiUrl}/extended/v1/info/network_block_times`,this.getPoxInfoUrl=()=>`${this.coreApiUrl}/v2/pox`,this.getRewardsUrl=(t,s)=>{let e=`${this.coreApiUrl}/extended/v1/burnchain/rewards/${t}`;return s&&(e=`${e}?limit=${s.limit}&offset=${s.offset}`),e},this.getRewardsTotalUrl=t=>`${this.coreApiUrl}/extended/v1/burnchain/rewards/${t}/total`,this.getRewardHoldersUrl=(t,s)=>{let e=`${this.coreApiUrl}/extended/v1/burnchain/reward_slot_holders/${t}`;return s&&(e=`${e}?limit=${s.limit}&offset=${s.offset}`),e},this.getStackerInfoUrl=(t,s)=>`${this.coreApiUrl}${this.readOnlyFunctionCallEndpoint}\n ${t}/${s}/get-stacker-info`,this.coreApiUrl=e.url}getNameInfo(t){const s=`${this.bnsLookupUrl}/v1/names/${t}`;return e(s).then((t=>{if(404===t.status)throw new Error("Name not found");if(200!==t.status)throw new Error(`Bad response status: ${t.status}`);return t.json()})).then((t=>t.address?Object.assign({},t,{address:t.address}):t))}}a.fromName=t=>{switch(t){case"mainnet":return new c;case"testnet":return new l;default:throw new Error(`Invalid network name provided. Must be one of the following: ${o.join(", ")}`)}},a.fromNameOrNetwork=t=>"string"!=typeof t&&"version"in t?t:a.fromName(t);class c extends a{constructor(e={url:"https://stacks-node-api.mainnet.stacks.co"}){super(e),this.version=t.Mainnet,this.chainId=s.Mainnet}}class l extends a{constructor(e={url:"https://stacks-node-api.testnet.stacks.co"}){super(e),this.version=t.Testnet,this.chainId=s.Testnet}}class h extends a{constructor(e={url:"http://localhost:3999"}){super(e),this.version=t.Testnet,this.chainId=s.Testnet}}export{n as HIRO_MAINNET_DEFAULT,r as HIRO_MOCKNET_DEFAULT,i as HIRO_TESTNET_DEFAULT,c as StacksMainnet,h as StacksMocknet,a as StacksNetwork,o as StacksNetworks,l as StacksTestnet};
1
+ window.global=window;import{TransactionVersion as t,ChainID as e}from"@stacks/common/dist/polyfill";var r="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};!function(t){!function(e){var r="URLSearchParams"in t,n="Symbol"in t&&"iterator"in Symbol,o="FileReader"in t&&"Blob"in t&&function(){try{return new Blob,!0}catch(t){return!1}}(),i="FormData"in t,s="ArrayBuffer"in t;if(s)var a=["[object Int8Array]","[object Uint8Array]","[object Uint8ClampedArray]","[object Int16Array]","[object Uint16Array]","[object Int32Array]","[object Uint32Array]","[object Float32Array]","[object Float64Array]"],h=ArrayBuffer.isView||function(t){return t&&a.indexOf(Object.prototype.toString.call(t))>-1};function c(t){if("string"!=typeof t&&(t=String(t)),/[^a-z0-9\-#$%&'*+.^_`|~]/i.test(t))throw new TypeError("Invalid character in header field name");return t.toLowerCase()}function l(t){return"string"!=typeof t&&(t=String(t)),t}function d(t){var e={next:function(){var e=t.shift();return{done:void 0===e,value:e}}};return n&&(e[Symbol.iterator]=function(){return e}),e}function u(t){this.map={},t instanceof u?t.forEach((function(t,e){this.append(e,t)}),this):Array.isArray(t)?t.forEach((function(t){this.append(t[0],t[1])}),this):t&&Object.getOwnPropertyNames(t).forEach((function(e){this.append(e,t[e])}),this)}function f(t){if(t.bodyUsed)return Promise.reject(new TypeError("Already read"));t.bodyUsed=!0}function p(t){return new Promise((function(e,r){t.onload=function(){e(t.result)},t.onerror=function(){r(t.error)}}))}function y(t){var e=new FileReader,r=p(e);return e.readAsArrayBuffer(t),r}function b(t){if(t.slice)return t.slice(0);var e=new Uint8Array(t.byteLength);return e.set(new Uint8Array(t)),e.buffer}function m(){return this.bodyUsed=!1,this._initBody=function(t){var e;this._bodyInit=t,t?"string"==typeof t?this._bodyText=t:o&&Blob.prototype.isPrototypeOf(t)?this._bodyBlob=t:i&&FormData.prototype.isPrototypeOf(t)?this._bodyFormData=t:r&&URLSearchParams.prototype.isPrototypeOf(t)?this._bodyText=t.toString():s&&o&&(e=t)&&DataView.prototype.isPrototypeOf(e)?(this._bodyArrayBuffer=b(t.buffer),this._bodyInit=new Blob([this._bodyArrayBuffer])):s&&(ArrayBuffer.prototype.isPrototypeOf(t)||h(t))?this._bodyArrayBuffer=b(t):this._bodyText=t=Object.prototype.toString.call(t):this._bodyText="",this.headers.get("content-type")||("string"==typeof t?this.headers.set("content-type","text/plain;charset=UTF-8"):this._bodyBlob&&this._bodyBlob.type?this.headers.set("content-type",this._bodyBlob.type):r&&URLSearchParams.prototype.isPrototypeOf(t)&&this.headers.set("content-type","application/x-www-form-urlencoded;charset=UTF-8"))},o&&(this.blob=function(){var t=f(this);if(t)return t;if(this._bodyBlob)return Promise.resolve(this._bodyBlob);if(this._bodyArrayBuffer)return Promise.resolve(new Blob([this._bodyArrayBuffer]));if(this._bodyFormData)throw new Error("could not read FormData body as blob");return Promise.resolve(new Blob([this._bodyText]))},this.arrayBuffer=function(){return this._bodyArrayBuffer?f(this)||Promise.resolve(this._bodyArrayBuffer):this.blob().then(y)}),this.text=function(){var t,e,r,n=f(this);if(n)return n;if(this._bodyBlob)return t=this._bodyBlob,e=new FileReader,r=p(e),e.readAsText(t),r;if(this._bodyArrayBuffer)return Promise.resolve(function(t){for(var e=new Uint8Array(t),r=new Array(e.length),n=0;n<e.length;n++)r[n]=String.fromCharCode(e[n]);return r.join("")}(this._bodyArrayBuffer));if(this._bodyFormData)throw new Error("could not read FormData body as text");return Promise.resolve(this._bodyText)},i&&(this.formData=function(){return this.text().then(g)}),this.json=function(){return this.text().then(JSON.parse)},this}u.prototype.append=function(t,e){t=c(t),e=l(e);var r=this.map[t];this.map[t]=r?r+", "+e:e},u.prototype.delete=function(t){delete this.map[c(t)]},u.prototype.get=function(t){return t=c(t),this.has(t)?this.map[t]:null},u.prototype.has=function(t){return this.map.hasOwnProperty(c(t))},u.prototype.set=function(t,e){this.map[c(t)]=l(e)},u.prototype.forEach=function(t,e){for(var r in this.map)this.map.hasOwnProperty(r)&&t.call(e,this.map[r],r,this)},u.prototype.keys=function(){var t=[];return this.forEach((function(e,r){t.push(r)})),d(t)},u.prototype.values=function(){var t=[];return this.forEach((function(e){t.push(e)})),d(t)},u.prototype.entries=function(){var t=[];return this.forEach((function(e,r){t.push([r,e])})),d(t)},n&&(u.prototype[Symbol.iterator]=u.prototype.entries);var w=["DELETE","GET","HEAD","OPTIONS","POST","PUT"];function v(t,e){var r,n,o=(e=e||{}).body;if(t instanceof v){if(t.bodyUsed)throw new TypeError("Already read");this.url=t.url,this.credentials=t.credentials,e.headers||(this.headers=new u(t.headers)),this.method=t.method,this.mode=t.mode,this.signal=t.signal,o||null==t._bodyInit||(o=t._bodyInit,t.bodyUsed=!0)}else this.url=String(t);if(this.credentials=e.credentials||this.credentials||"same-origin",!e.headers&&this.headers||(this.headers=new u(e.headers)),this.method=(r=e.method||this.method||"GET",n=r.toUpperCase(),w.indexOf(n)>-1?n:r),this.mode=e.mode||this.mode||null,this.signal=e.signal||this.signal,this.referrer=null,("GET"===this.method||"HEAD"===this.method)&&o)throw new TypeError("Body not allowed for GET or HEAD requests");this._initBody(o)}function g(t){var e=new FormData;return t.trim().split("&").forEach((function(t){if(t){var r=t.split("="),n=r.shift().replace(/\+/g," "),o=r.join("=").replace(/\+/g," ");e.append(decodeURIComponent(n),decodeURIComponent(o))}})),e}function E(t,e){e||(e={}),this.type="default",this.status=void 0===e.status?200:e.status,this.ok=this.status>=200&&this.status<300,this.statusText="statusText"in e?e.statusText:"OK",this.headers=new u(e.headers),this.url=e.url||"",this._initBody(t)}v.prototype.clone=function(){return new v(this,{body:this._bodyInit})},m.call(v.prototype),m.call(E.prototype),E.prototype.clone=function(){return new E(this._bodyInit,{status:this.status,statusText:this.statusText,headers:new u(this.headers),url:this.url})},E.error=function(){var t=new E(null,{status:0,statusText:""});return t.type="error",t};var A=[301,302,303,307,308];E.redirect=function(t,e){if(-1===A.indexOf(e))throw new RangeError("Invalid status code");return new E(null,{status:e,headers:{location:t}})},e.DOMException=t.DOMException;try{new e.DOMException}catch(t){e.DOMException=function(t,e){this.message=t,this.name=e;var r=Error(t);this.stack=r.stack},e.DOMException.prototype=Object.create(Error.prototype),e.DOMException.prototype.constructor=e.DOMException}function U(t,r){return new Promise((function(n,i){var s=new v(t,r);if(s.signal&&s.signal.aborted)return i(new e.DOMException("Aborted","AbortError"));var a=new XMLHttpRequest;function h(){a.abort()}a.onload=function(){var t,e,r={status:a.status,statusText:a.statusText,headers:(t=a.getAllResponseHeaders()||"",e=new u,t.replace(/\r?\n[\t ]+/g," ").split(/\r?\n/).forEach((function(t){var r=t.split(":"),n=r.shift().trim();if(n){var o=r.join(":").trim();e.append(n,o)}})),e)};r.url="responseURL"in a?a.responseURL:r.headers.get("X-Request-URL");var o="response"in a?a.response:a.responseText;n(new E(o,r))},a.onerror=function(){i(new TypeError("Network request failed"))},a.ontimeout=function(){i(new TypeError("Network request failed"))},a.onabort=function(){i(new e.DOMException("Aborted","AbortError"))},a.open(s.method,s.url,!0),"include"===s.credentials?a.withCredentials=!0:"omit"===s.credentials&&(a.withCredentials=!1),"responseType"in a&&o&&(a.responseType="blob"),s.headers.forEach((function(t,e){a.setRequestHeader(e,t)})),s.signal&&(s.signal.addEventListener("abort",h),a.onreadystatechange=function(){4===a.readyState&&s.signal.removeEventListener("abort",h)}),a.send(void 0===s._bodyInit?null:s._bodyInit)}))}U.polyfill=!0,t.fetch||(t.fetch=U,t.Headers=u,t.Request=v,t.Response=E),e.Headers=u,e.Request=v,e.Response=E,e.fetch=U,Object.defineProperty(e,"__esModule",{value:!0})}({})}("undefined"!=typeof self?self:r);const n={referrerPolicy:"origin"},o=()=>n,i=t=>Object.assign(n,t);async function s(t,e){const r={};Object.assign(r,e,n);return await fetch(t,r)}function a(t,e){return"string"==typeof e?e===t:e.exec(t)}function h({apiKey:t,host:e=/(.*)api(.*)\.stacks\.co$/i,httpHeader:r="x-api-key"}){return{pre:n=>{if(!a(new URL(n.url).host,e))return;const o=new Headers(n.init.headers);o.set(r,t),n.init.headers=o}}}function c(...t){const{fetchLib:e,middlewares:r}=function(t){let e=s,r=[];return t.length>0&&"function"==typeof t[0]&&(e=t.shift()),t.length>0&&(r=t),{fetchLib:e,middlewares:r}}(t);return async(t,n)=>{var o;let i={url:t,init:null!=n?n:{}};for(const t of r)if("function"==typeof t.pre){const r=await Promise.resolve(t.pre(Object.assign({fetch:e},i)));i=null!=r?r:i}let s=await e(i.url,i.init);for(const t of r)if("function"==typeof t.post){const r=await Promise.resolve(t.post({fetch:e,url:i.url,init:i.init,response:null!==(o=null==s?void 0:s.clone())&&void 0!==o?o:s}));s=null!=r?r:s}return s}}const l="https://stacks-node-api.mainnet.stacks.co",d="https://stacks-node-api.testnet.stacks.co",u="http://localhost:3999",f=["mainnet","testnet"];class p{constructor(r){var n;this.version=t.Mainnet,this.chainId=e.Mainnet,this.bnsLookupUrl="https://stacks-node-api.mainnet.stacks.co",this.broadcastEndpoint="/v2/transactions",this.transferFeeEstimateEndpoint="/v2/fees/transfer",this.transactionFeeEstimateEndpoint="/v2/fees/transaction",this.accountEndpoint="/v2/accounts",this.contractAbiEndpoint="/v2/contracts/interface",this.readOnlyFunctionCallEndpoint="/v2/contracts/call-read",this.isMainnet=()=>this.version===t.Mainnet,this.getBroadcastApiUrl=()=>`${this.coreApiUrl}${this.broadcastEndpoint}`,this.getTransferFeeEstimateApiUrl=()=>`${this.coreApiUrl}${this.transferFeeEstimateEndpoint}`,this.getTransactionFeeEstimateApiUrl=()=>`${this.coreApiUrl}${this.transactionFeeEstimateEndpoint}`,this.getAccountApiUrl=t=>`${this.coreApiUrl}${this.accountEndpoint}/${t}?proof=0`,this.getAbiApiUrl=(t,e)=>`${this.coreApiUrl}${this.contractAbiEndpoint}/${t}/${e}`,this.getReadOnlyFunctionCallApiUrl=(t,e,r)=>`${this.coreApiUrl}${this.readOnlyFunctionCallEndpoint}/${t}/${e}/${encodeURIComponent(r)}`,this.getInfoUrl=()=>`${this.coreApiUrl}/v2/info`,this.getBlockTimeInfoUrl=()=>`${this.coreApiUrl}/extended/v1/info/network_block_times`,this.getPoxInfoUrl=()=>`${this.coreApiUrl}/v2/pox`,this.getRewardsUrl=(t,e)=>{let r=`${this.coreApiUrl}/extended/v1/burnchain/rewards/${t}`;return e&&(r=`${r}?limit=${e.limit}&offset=${e.offset}`),r},this.getRewardsTotalUrl=t=>`${this.coreApiUrl}/extended/v1/burnchain/rewards/${t}/total`,this.getRewardHoldersUrl=(t,e)=>{let r=`${this.coreApiUrl}/extended/v1/burnchain/reward_slot_holders/${t}`;return e&&(r=`${r}?limit=${e.limit}&offset=${e.offset}`),r},this.getStackerInfoUrl=(t,e)=>`${this.coreApiUrl}${this.readOnlyFunctionCallEndpoint}\n ${t}/${e}/get-stacker-info`,this.coreApiUrl=r.url,this.fetchFn=null!==(n=r.fetchFn)&&void 0!==n?n:c()}getNameInfo(t){const e=`${this.bnsLookupUrl}/v1/names/${t}`;return this.fetchFn(e).then((t=>{if(404===t.status)throw new Error("Name not found");if(200!==t.status)throw new Error(`Bad response status: ${t.status}`);return t.json()})).then((t=>t.address?Object.assign({},t,{address:t.address}):t))}}p.fromName=t=>{switch(t){case"mainnet":return new y;case"testnet":return new b;default:throw new Error(`Invalid network name provided. Must be one of the following: ${f.join(", ")}`)}},p.fromNameOrNetwork=t=>"string"!=typeof t&&"version"in t?t:p.fromName(t);class y extends p{constructor(r){var n;super({url:null!==(n=null==r?void 0:r.url)&&void 0!==n?n:"https://stacks-node-api.mainnet.stacks.co",fetchFn:null==r?void 0:r.fetchFn}),this.version=t.Mainnet,this.chainId=e.Mainnet}}class b extends p{constructor(r){var n;super({url:null!==(n=null==r?void 0:r.url)&&void 0!==n?n:"https://stacks-node-api.testnet.stacks.co",fetchFn:null==r?void 0:r.fetchFn}),this.version=t.Testnet,this.chainId=e.Testnet}}class m extends p{constructor(r){var n;super({url:null!==(n=null==r?void 0:r.url)&&void 0!==n?n:"http://localhost:3999",fetchFn:null==r?void 0:r.fetchFn}),this.version=t.Testnet,this.chainId=e.Testnet}}export{l as HIRO_MAINNET_DEFAULT,u as HIRO_MOCKNET_DEFAULT,d as HIRO_TESTNET_DEFAULT,y as StacksMainnet,m as StacksMocknet,p as StacksNetwork,f as StacksNetworks,b as StacksTestnet,h as createApiKeyMiddleware,c as createFetchFn,s as fetchWrapper,o as getFetchOptions,a as hostMatches,i as setFetchOptions};
package/dist/umd/index.js CHANGED
@@ -1,2 +1,2 @@
1
- !function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.StacksNetwork=e():t.StacksNetwork=e()}(this,(()=>(()=>{var t={616:function(){!function(t){!function(e){var r="URLSearchParams"in t,n="Symbol"in t&&"iterator"in Symbol,o="FileReader"in t&&"Blob"in t&&function(){try{return new Blob,!0}catch(t){return!1}}(),i="FormData"in t,s="ArrayBuffer"in t;if(s)var a=["[object Int8Array]","[object Uint8Array]","[object Uint8ClampedArray]","[object Int16Array]","[object Uint16Array]","[object Int32Array]","[object Uint32Array]","[object Float32Array]","[object Float64Array]"],c=ArrayBuffer.isView||function(t){return t&&a.indexOf(Object.prototype.toString.call(t))>-1};function h(t){if("string"!=typeof t&&(t=String(t)),/[^a-z0-9\-#$%&'*+.^_`|~]/i.test(t))throw new TypeError("Invalid character in header field name");return t.toLowerCase()}function d(t){return"string"!=typeof t&&(t=String(t)),t}function u(t){var e={next:function(){var e=t.shift();return{done:void 0===e,value:e}}};return n&&(e[Symbol.iterator]=function(){return e}),e}function l(t){this.map={},t instanceof l?t.forEach((function(t,e){this.append(e,t)}),this):Array.isArray(t)?t.forEach((function(t){this.append(t[0],t[1])}),this):t&&Object.getOwnPropertyNames(t).forEach((function(e){this.append(e,t[e])}),this)}function p(t){if(t.bodyUsed)return Promise.reject(new TypeError("Already read"));t.bodyUsed=!0}function f(t){return new Promise((function(e,r){t.onload=function(){e(t.result)},t.onerror=function(){r(t.error)}}))}function y(t){var e=new FileReader,r=f(e);return e.readAsArrayBuffer(t),r}function b(t){if(t.slice)return t.slice(0);var e=new Uint8Array(t.byteLength);return e.set(new Uint8Array(t)),e.buffer}function m(){return this.bodyUsed=!1,this._initBody=function(t){var e;this._bodyInit=t,t?"string"==typeof t?this._bodyText=t:o&&Blob.prototype.isPrototypeOf(t)?this._bodyBlob=t:i&&FormData.prototype.isPrototypeOf(t)?this._bodyFormData=t:r&&URLSearchParams.prototype.isPrototypeOf(t)?this._bodyText=t.toString():s&&o&&(e=t)&&DataView.prototype.isPrototypeOf(e)?(this._bodyArrayBuffer=b(t.buffer),this._bodyInit=new Blob([this._bodyArrayBuffer])):s&&(ArrayBuffer.prototype.isPrototypeOf(t)||c(t))?this._bodyArrayBuffer=b(t):this._bodyText=t=Object.prototype.toString.call(t):this._bodyText="",this.headers.get("content-type")||("string"==typeof t?this.headers.set("content-type","text/plain;charset=UTF-8"):this._bodyBlob&&this._bodyBlob.type?this.headers.set("content-type",this._bodyBlob.type):r&&URLSearchParams.prototype.isPrototypeOf(t)&&this.headers.set("content-type","application/x-www-form-urlencoded;charset=UTF-8"))},o&&(this.blob=function(){var t=p(this);if(t)return t;if(this._bodyBlob)return Promise.resolve(this._bodyBlob);if(this._bodyArrayBuffer)return Promise.resolve(new Blob([this._bodyArrayBuffer]));if(this._bodyFormData)throw new Error("could not read FormData body as blob");return Promise.resolve(new Blob([this._bodyText]))},this.arrayBuffer=function(){return this._bodyArrayBuffer?p(this)||Promise.resolve(this._bodyArrayBuffer):this.blob().then(y)}),this.text=function(){var t,e,r,n=p(this);if(n)return n;if(this._bodyBlob)return t=this._bodyBlob,r=f(e=new FileReader),e.readAsText(t),r;if(this._bodyArrayBuffer)return Promise.resolve(function(t){for(var e=new Uint8Array(t),r=new Array(e.length),n=0;n<e.length;n++)r[n]=String.fromCharCode(e[n]);return r.join("")}(this._bodyArrayBuffer));if(this._bodyFormData)throw new Error("could not read FormData body as text");return Promise.resolve(this._bodyText)},i&&(this.formData=function(){return this.text().then(E)}),this.json=function(){return this.text().then(JSON.parse)},this}l.prototype.append=function(t,e){t=h(t),e=d(e);var r=this.map[t];this.map[t]=r?r+", "+e:e},l.prototype.delete=function(t){delete this.map[h(t)]},l.prototype.get=function(t){return t=h(t),this.has(t)?this.map[t]:null},l.prototype.has=function(t){return this.map.hasOwnProperty(h(t))},l.prototype.set=function(t,e){this.map[h(t)]=d(e)},l.prototype.forEach=function(t,e){for(var r in this.map)this.map.hasOwnProperty(r)&&t.call(e,this.map[r],r,this)},l.prototype.keys=function(){var t=[];return this.forEach((function(e,r){t.push(r)})),u(t)},l.prototype.values=function(){var t=[];return this.forEach((function(e){t.push(e)})),u(t)},l.prototype.entries=function(){var t=[];return this.forEach((function(e,r){t.push([r,e])})),u(t)},n&&(l.prototype[Symbol.iterator]=l.prototype.entries);var w=["DELETE","GET","HEAD","OPTIONS","POST","PUT"];function v(t,e){var r,n,o=(e=e||{}).body;if(t instanceof v){if(t.bodyUsed)throw new TypeError("Already read");this.url=t.url,this.credentials=t.credentials,e.headers||(this.headers=new l(t.headers)),this.method=t.method,this.mode=t.mode,this.signal=t.signal,o||null==t._bodyInit||(o=t._bodyInit,t.bodyUsed=!0)}else this.url=String(t);if(this.credentials=e.credentials||this.credentials||"same-origin",!e.headers&&this.headers||(this.headers=new l(e.headers)),this.method=(n=(r=e.method||this.method||"GET").toUpperCase(),w.indexOf(n)>-1?n:r),this.mode=e.mode||this.mode||null,this.signal=e.signal||this.signal,this.referrer=null,("GET"===this.method||"HEAD"===this.method)&&o)throw new TypeError("Body not allowed for GET or HEAD requests");this._initBody(o)}function E(t){var e=new FormData;return t.trim().split("&").forEach((function(t){if(t){var r=t.split("="),n=r.shift().replace(/\+/g," "),o=r.join("=").replace(/\+/g," ");e.append(decodeURIComponent(n),decodeURIComponent(o))}})),e}function A(t,e){e||(e={}),this.type="default",this.status=void 0===e.status?200:e.status,this.ok=this.status>=200&&this.status<300,this.statusText="statusText"in e?e.statusText:"OK",this.headers=new l(e.headers),this.url=e.url||"",this._initBody(t)}v.prototype.clone=function(){return new v(this,{body:this._bodyInit})},m.call(v.prototype),m.call(A.prototype),A.prototype.clone=function(){return new A(this._bodyInit,{status:this.status,statusText:this.statusText,headers:new l(this.headers),url:this.url})},A.error=function(){var t=new A(null,{status:0,statusText:""});return t.type="error",t};var g=[301,302,303,307,308];A.redirect=function(t,e){if(-1===g.indexOf(e))throw new RangeError("Invalid status code");return new A(null,{status:e,headers:{location:t}})},e.DOMException=t.DOMException;try{new e.DOMException}catch(t){e.DOMException=function(t,e){this.message=t,this.name=e;var r=Error(t);this.stack=r.stack},e.DOMException.prototype=Object.create(Error.prototype),e.DOMException.prototype.constructor=e.DOMException}function T(t,r){return new Promise((function(n,i){var s=new v(t,r);if(s.signal&&s.signal.aborted)return i(new e.DOMException("Aborted","AbortError"));var a=new XMLHttpRequest;function c(){a.abort()}a.onload=function(){var t,e,r={status:a.status,statusText:a.statusText,headers:(t=a.getAllResponseHeaders()||"",e=new l,t.replace(/\r?\n[\t ]+/g," ").split(/\r?\n/).forEach((function(t){var r=t.split(":"),n=r.shift().trim();if(n){var o=r.join(":").trim();e.append(n,o)}})),e)};r.url="responseURL"in a?a.responseURL:r.headers.get("X-Request-URL");var o="response"in a?a.response:a.responseText;n(new A(o,r))},a.onerror=function(){i(new TypeError("Network request failed"))},a.ontimeout=function(){i(new TypeError("Network request failed"))},a.onabort=function(){i(new e.DOMException("Aborted","AbortError"))},a.open(s.method,s.url,!0),"include"===s.credentials?a.withCredentials=!0:"omit"===s.credentials&&(a.withCredentials=!1),"responseType"in a&&o&&(a.responseType="blob"),s.headers.forEach((function(t,e){a.setRequestHeader(e,t)})),s.signal&&(s.signal.addEventListener("abort",c),a.onreadystatechange=function(){4===a.readyState&&s.signal.removeEventListener("abort",c)}),a.send(void 0===s._bodyInit?null:s._bodyInit)}))}T.polyfill=!0,t.fetch||(t.fetch=T,t.Headers=l,t.Request=v,t.Response=A),e.Headers=l,e.Request=v,e.Response=A,e.fetch=T,Object.defineProperty(e,"__esModule",{value:!0})}({})}("undefined"!=typeof self?self:this)}},e={};function r(n){var o=e[n];if(void 0!==o)return o.exports;var i=e[n]={exports:{}};return t[n].call(i.exports,i,i.exports,r),i.exports}r.d=(t,e)=>{for(var n in e)r.o(e,n)&&!r.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:e[n]})},r.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var n={};return(()=>{"use strict";var t,e;r.r(n),r.d(n,{HIRO_MAINNET_DEFAULT:()=>i,HIRO_MOCKNET_DEFAULT:()=>a,HIRO_TESTNET_DEFAULT:()=>s,StacksMainnet:()=>u,StacksMocknet:()=>p,StacksNetwork:()=>d,StacksNetworks:()=>c,StacksTestnet:()=>l}),function(t){t[t.Testnet=2147483648]="Testnet",t[t.Mainnet=1]="Mainnet"}(t||(t={})),function(t){t[t.Mainnet=0]="Mainnet",t[t.Testnet=128]="Testnet"}(e||(e={})),r(616);const o={referrerPolicy:"origin"},i="https://stacks-node-api.mainnet.stacks.co",s="https://stacks-node-api.testnet.stacks.co",a="http://localhost:3999",c=["mainnet","testnet"],h=class{constructor(r){this.version=e.Mainnet,this.chainId=t.Mainnet,this.bnsLookupUrl="https://stacks-node-api.mainnet.stacks.co",this.broadcastEndpoint="/v2/transactions",this.transferFeeEstimateEndpoint="/v2/fees/transfer",this.transactionFeeEstimateEndpoint="/v2/fees/transaction",this.accountEndpoint="/v2/accounts",this.contractAbiEndpoint="/v2/contracts/interface",this.readOnlyFunctionCallEndpoint="/v2/contracts/call-read",this.isMainnet=()=>this.version===e.Mainnet,this.getBroadcastApiUrl=()=>`${this.coreApiUrl}${this.broadcastEndpoint}`,this.getTransferFeeEstimateApiUrl=()=>`${this.coreApiUrl}${this.transferFeeEstimateEndpoint}`,this.getTransactionFeeEstimateApiUrl=()=>`${this.coreApiUrl}${this.transactionFeeEstimateEndpoint}`,this.getAccountApiUrl=t=>`${this.coreApiUrl}${this.accountEndpoint}/${t}?proof=0`,this.getAbiApiUrl=(t,e)=>`${this.coreApiUrl}${this.contractAbiEndpoint}/${t}/${e}`,this.getReadOnlyFunctionCallApiUrl=(t,e,r)=>`${this.coreApiUrl}${this.readOnlyFunctionCallEndpoint}/${t}/${e}/${encodeURIComponent(r)}`,this.getInfoUrl=()=>`${this.coreApiUrl}/v2/info`,this.getBlockTimeInfoUrl=()=>`${this.coreApiUrl}/extended/v1/info/network_block_times`,this.getPoxInfoUrl=()=>`${this.coreApiUrl}/v2/pox`,this.getRewardsUrl=(t,e)=>{let r=`${this.coreApiUrl}/extended/v1/burnchain/rewards/${t}`;return e&&(r=`${r}?limit=${e.limit}&offset=${e.offset}`),r},this.getRewardsTotalUrl=t=>`${this.coreApiUrl}/extended/v1/burnchain/rewards/${t}/total`,this.getRewardHoldersUrl=(t,e)=>{let r=`${this.coreApiUrl}/extended/v1/burnchain/reward_slot_holders/${t}`;return e&&(r=`${r}?limit=${e.limit}&offset=${e.offset}`),r},this.getStackerInfoUrl=(t,e)=>`${this.coreApiUrl}${this.readOnlyFunctionCallEndpoint}\n ${t}/${e}/get-stacker-info`,this.coreApiUrl=r.url}getNameInfo(t){return async function(t,e){const r={};return Object.assign(r,void 0,o),await fetch(t,r)}(`${this.bnsLookupUrl}/v1/names/${t}`).then((t=>{if(404===t.status)throw new Error("Name not found");if(200!==t.status)throw new Error(`Bad response status: ${t.status}`);return t.json()})).then((t=>t.address?Object.assign({},t,{address:t.address}):t))}};let d=h;d.fromName=t=>{switch(t){case"mainnet":return new u;case"testnet":return new l;default:throw new Error(`Invalid network name provided. Must be one of the following: ${c.join(", ")}`)}},d.fromNameOrNetwork=t=>"string"!=typeof t&&"version"in t?t:h.fromName(t);class u extends d{constructor(r={url:i}){super(r),this.version=e.Mainnet,this.chainId=t.Mainnet}}class l extends d{constructor(r={url:s}){super(r),this.version=e.Testnet,this.chainId=t.Testnet}}class p extends d{constructor(r={url:a}){super(r),this.version=e.Testnet,this.chainId=t.Testnet}}})(),n})()));
1
+ !function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.StacksNetwork=e():t.StacksNetwork=e()}(this,(()=>(()=>{var t={616:function(){!function(t){!function(e){var r="URLSearchParams"in t,n="Symbol"in t&&"iterator"in Symbol,o="FileReader"in t&&"Blob"in t&&function(){try{return new Blob,!0}catch(t){return!1}}(),i="FormData"in t,s="ArrayBuffer"in t;if(s)var a=["[object Int8Array]","[object Uint8Array]","[object Uint8ClampedArray]","[object Int16Array]","[object Uint16Array]","[object Int32Array]","[object Uint32Array]","[object Float32Array]","[object Float64Array]"],c=ArrayBuffer.isView||function(t){return t&&a.indexOf(Object.prototype.toString.call(t))>-1};function h(t){if("string"!=typeof t&&(t=String(t)),/[^a-z0-9\-#$%&'*+.^_`|~]/i.test(t))throw new TypeError("Invalid character in header field name");return t.toLowerCase()}function l(t){return"string"!=typeof t&&(t=String(t)),t}function u(t){var e={next:function(){var e=t.shift();return{done:void 0===e,value:e}}};return n&&(e[Symbol.iterator]=function(){return e}),e}function f(t){this.map={},t instanceof f?t.forEach((function(t,e){this.append(e,t)}),this):Array.isArray(t)?t.forEach((function(t){this.append(t[0],t[1])}),this):t&&Object.getOwnPropertyNames(t).forEach((function(e){this.append(e,t[e])}),this)}function d(t){if(t.bodyUsed)return Promise.reject(new TypeError("Already read"));t.bodyUsed=!0}function p(t){return new Promise((function(e,r){t.onload=function(){e(t.result)},t.onerror=function(){r(t.error)}}))}function y(t){var e=new FileReader,r=p(e);return e.readAsArrayBuffer(t),r}function b(t){if(t.slice)return t.slice(0);var e=new Uint8Array(t.byteLength);return e.set(new Uint8Array(t)),e.buffer}function m(){return this.bodyUsed=!1,this._initBody=function(t){var e;this._bodyInit=t,t?"string"==typeof t?this._bodyText=t:o&&Blob.prototype.isPrototypeOf(t)?this._bodyBlob=t:i&&FormData.prototype.isPrototypeOf(t)?this._bodyFormData=t:r&&URLSearchParams.prototype.isPrototypeOf(t)?this._bodyText=t.toString():s&&o&&(e=t)&&DataView.prototype.isPrototypeOf(e)?(this._bodyArrayBuffer=b(t.buffer),this._bodyInit=new Blob([this._bodyArrayBuffer])):s&&(ArrayBuffer.prototype.isPrototypeOf(t)||c(t))?this._bodyArrayBuffer=b(t):this._bodyText=t=Object.prototype.toString.call(t):this._bodyText="",this.headers.get("content-type")||("string"==typeof t?this.headers.set("content-type","text/plain;charset=UTF-8"):this._bodyBlob&&this._bodyBlob.type?this.headers.set("content-type",this._bodyBlob.type):r&&URLSearchParams.prototype.isPrototypeOf(t)&&this.headers.set("content-type","application/x-www-form-urlencoded;charset=UTF-8"))},o&&(this.blob=function(){var t=d(this);if(t)return t;if(this._bodyBlob)return Promise.resolve(this._bodyBlob);if(this._bodyArrayBuffer)return Promise.resolve(new Blob([this._bodyArrayBuffer]));if(this._bodyFormData)throw new Error("could not read FormData body as blob");return Promise.resolve(new Blob([this._bodyText]))},this.arrayBuffer=function(){return this._bodyArrayBuffer?d(this)||Promise.resolve(this._bodyArrayBuffer):this.blob().then(y)}),this.text=function(){var t,e,r,n=d(this);if(n)return n;if(this._bodyBlob)return t=this._bodyBlob,r=p(e=new FileReader),e.readAsText(t),r;if(this._bodyArrayBuffer)return Promise.resolve(function(t){for(var e=new Uint8Array(t),r=new Array(e.length),n=0;n<e.length;n++)r[n]=String.fromCharCode(e[n]);return r.join("")}(this._bodyArrayBuffer));if(this._bodyFormData)throw new Error("could not read FormData body as text");return Promise.resolve(this._bodyText)},i&&(this.formData=function(){return this.text().then(E)}),this.json=function(){return this.text().then(JSON.parse)},this}f.prototype.append=function(t,e){t=h(t),e=l(e);var r=this.map[t];this.map[t]=r?r+", "+e:e},f.prototype.delete=function(t){delete this.map[h(t)]},f.prototype.get=function(t){return t=h(t),this.has(t)?this.map[t]:null},f.prototype.has=function(t){return this.map.hasOwnProperty(h(t))},f.prototype.set=function(t,e){this.map[h(t)]=l(e)},f.prototype.forEach=function(t,e){for(var r in this.map)this.map.hasOwnProperty(r)&&t.call(e,this.map[r],r,this)},f.prototype.keys=function(){var t=[];return this.forEach((function(e,r){t.push(r)})),u(t)},f.prototype.values=function(){var t=[];return this.forEach((function(e){t.push(e)})),u(t)},f.prototype.entries=function(){var t=[];return this.forEach((function(e,r){t.push([r,e])})),u(t)},n&&(f.prototype[Symbol.iterator]=f.prototype.entries);var v=["DELETE","GET","HEAD","OPTIONS","POST","PUT"];function w(t,e){var r,n,o=(e=e||{}).body;if(t instanceof w){if(t.bodyUsed)throw new TypeError("Already read");this.url=t.url,this.credentials=t.credentials,e.headers||(this.headers=new f(t.headers)),this.method=t.method,this.mode=t.mode,this.signal=t.signal,o||null==t._bodyInit||(o=t._bodyInit,t.bodyUsed=!0)}else this.url=String(t);if(this.credentials=e.credentials||this.credentials||"same-origin",!e.headers&&this.headers||(this.headers=new f(e.headers)),this.method=(n=(r=e.method||this.method||"GET").toUpperCase(),v.indexOf(n)>-1?n:r),this.mode=e.mode||this.mode||null,this.signal=e.signal||this.signal,this.referrer=null,("GET"===this.method||"HEAD"===this.method)&&o)throw new TypeError("Body not allowed for GET or HEAD requests");this._initBody(o)}function E(t){var e=new FormData;return t.trim().split("&").forEach((function(t){if(t){var r=t.split("="),n=r.shift().replace(/\+/g," "),o=r.join("=").replace(/\+/g," ");e.append(decodeURIComponent(n),decodeURIComponent(o))}})),e}function A(t,e){e||(e={}),this.type="default",this.status=void 0===e.status?200:e.status,this.ok=this.status>=200&&this.status<300,this.statusText="statusText"in e?e.statusText:"OK",this.headers=new f(e.headers),this.url=e.url||"",this._initBody(t)}w.prototype.clone=function(){return new w(this,{body:this._bodyInit})},m.call(w.prototype),m.call(A.prototype),A.prototype.clone=function(){return new A(this._bodyInit,{status:this.status,statusText:this.statusText,headers:new f(this.headers),url:this.url})},A.error=function(){var t=new A(null,{status:0,statusText:""});return t.type="error",t};var g=[301,302,303,307,308];A.redirect=function(t,e){if(-1===g.indexOf(e))throw new RangeError("Invalid status code");return new A(null,{status:e,headers:{location:t}})},e.DOMException=t.DOMException;try{new e.DOMException}catch(t){e.DOMException=function(t,e){this.message=t,this.name=e;var r=Error(t);this.stack=r.stack},e.DOMException.prototype=Object.create(Error.prototype),e.DOMException.prototype.constructor=e.DOMException}function U(t,r){return new Promise((function(n,i){var s=new w(t,r);if(s.signal&&s.signal.aborted)return i(new e.DOMException("Aborted","AbortError"));var a=new XMLHttpRequest;function c(){a.abort()}a.onload=function(){var t,e,r={status:a.status,statusText:a.statusText,headers:(t=a.getAllResponseHeaders()||"",e=new f,t.replace(/\r?\n[\t ]+/g," ").split(/\r?\n/).forEach((function(t){var r=t.split(":"),n=r.shift().trim();if(n){var o=r.join(":").trim();e.append(n,o)}})),e)};r.url="responseURL"in a?a.responseURL:r.headers.get("X-Request-URL");var o="response"in a?a.response:a.responseText;n(new A(o,r))},a.onerror=function(){i(new TypeError("Network request failed"))},a.ontimeout=function(){i(new TypeError("Network request failed"))},a.onabort=function(){i(new e.DOMException("Aborted","AbortError"))},a.open(s.method,s.url,!0),"include"===s.credentials?a.withCredentials=!0:"omit"===s.credentials&&(a.withCredentials=!1),"responseType"in a&&o&&(a.responseType="blob"),s.headers.forEach((function(t,e){a.setRequestHeader(e,t)})),s.signal&&(s.signal.addEventListener("abort",c),a.onreadystatechange=function(){4===a.readyState&&s.signal.removeEventListener("abort",c)}),a.send(void 0===s._bodyInit?null:s._bodyInit)}))}U.polyfill=!0,t.fetch||(t.fetch=U,t.Headers=f,t.Request=w,t.Response=A),e.Headers=f,e.Request=w,e.Response=A,e.fetch=U,Object.defineProperty(e,"__esModule",{value:!0})}({})}("undefined"!=typeof self?self:this)}},e={};function r(n){var o=e[n];if(void 0!==o)return o.exports;var i=e[n]={exports:{}};return t[n].call(i.exports,i,i.exports,r),i.exports}r.d=(t,e)=>{for(var n in e)r.o(e,n)&&!r.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:e[n]})},r.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var n={};return(()=>{"use strict";r.r(n),r.d(n,{HIRO_MAINNET_DEFAULT:()=>m,HIRO_MOCKNET_DEFAULT:()=>w,HIRO_TESTNET_DEFAULT:()=>v,StacksMainnet:()=>U,StacksMocknet:()=>O,StacksNetwork:()=>g,StacksNetworks:()=>E,StacksTestnet:()=>T,createApiKeyMiddleware:()=>d,createFetchFn:()=>p,fetchWrapper:()=>u,getFetchOptions:()=>h,hostMatches:()=>f,setFetchOptions:()=>l}),r(616);var t=Object.defineProperty,e=Object.getOwnPropertySymbols,o=Object.prototype.hasOwnProperty,i=Object.prototype.propertyIsEnumerable,s=(e,r,n)=>r in e?t(e,r,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[r]=n,a=(t,r)=>{for(var n in r||(r={}))o.call(r,n)&&s(t,n,r[n]);if(e)for(var n of e(r))i.call(r,n)&&s(t,n,r[n]);return t};const c={referrerPolicy:"origin"},h=()=>c,l=t=>Object.assign(c,t);async function u(t,e){const r={};return Object.assign(r,e,c),await fetch(t,r)}function f(t,e){return"string"==typeof e?e===t:e.exec(t)}function d({apiKey:t,host:e=/(.*)api(.*)\.stacks\.co$/i,httpHeader:r="x-api-key"}){return{pre:n=>{if(!f(new URL(n.url).host,e))return;const o=new Headers(n.init.headers);o.set(r,t),n.init.headers=o}}}function p(...t){const{fetchLib:e,middlewares:r}=function(t){let e=u,r=[];return t.length>0&&"function"==typeof t[0]&&(e=t.shift()),t.length>0&&(r=t),{fetchLib:e,middlewares:r}}(t);return async(t,n)=>{var o;let i={url:t,init:null!=n?n:{}};for(const t of r)if("function"==typeof t.pre){const r=await Promise.resolve(t.pre(a({fetch:e},i)));i=null!=r?r:i}let s=await e(i.url,i.init);for(const t of r)if("function"==typeof t.post){const r=await Promise.resolve(t.post({fetch:e,url:i.url,init:i.init,response:null!=(o=null==s?void 0:s.clone())?o:s}));s=null!=r?r:s}return s}}var y,b;!function(t){t[t.Testnet=2147483648]="Testnet",t[t.Mainnet=1]="Mainnet"}(y||(y={})),function(t){t[t.Mainnet=0]="Mainnet",t[t.Testnet=128]="Testnet"}(b||(b={}));const m="https://stacks-node-api.mainnet.stacks.co",v="https://stacks-node-api.testnet.stacks.co",w="http://localhost:3999",E=["mainnet","testnet"],A=class{constructor(t){var e;this.version=b.Mainnet,this.chainId=y.Mainnet,this.bnsLookupUrl="https://stacks-node-api.mainnet.stacks.co",this.broadcastEndpoint="/v2/transactions",this.transferFeeEstimateEndpoint="/v2/fees/transfer",this.transactionFeeEstimateEndpoint="/v2/fees/transaction",this.accountEndpoint="/v2/accounts",this.contractAbiEndpoint="/v2/contracts/interface",this.readOnlyFunctionCallEndpoint="/v2/contracts/call-read",this.isMainnet=()=>this.version===b.Mainnet,this.getBroadcastApiUrl=()=>`${this.coreApiUrl}${this.broadcastEndpoint}`,this.getTransferFeeEstimateApiUrl=()=>`${this.coreApiUrl}${this.transferFeeEstimateEndpoint}`,this.getTransactionFeeEstimateApiUrl=()=>`${this.coreApiUrl}${this.transactionFeeEstimateEndpoint}`,this.getAccountApiUrl=t=>`${this.coreApiUrl}${this.accountEndpoint}/${t}?proof=0`,this.getAbiApiUrl=(t,e)=>`${this.coreApiUrl}${this.contractAbiEndpoint}/${t}/${e}`,this.getReadOnlyFunctionCallApiUrl=(t,e,r)=>`${this.coreApiUrl}${this.readOnlyFunctionCallEndpoint}/${t}/${e}/${encodeURIComponent(r)}`,this.getInfoUrl=()=>`${this.coreApiUrl}/v2/info`,this.getBlockTimeInfoUrl=()=>`${this.coreApiUrl}/extended/v1/info/network_block_times`,this.getPoxInfoUrl=()=>`${this.coreApiUrl}/v2/pox`,this.getRewardsUrl=(t,e)=>{let r=`${this.coreApiUrl}/extended/v1/burnchain/rewards/${t}`;return e&&(r=`${r}?limit=${e.limit}&offset=${e.offset}`),r},this.getRewardsTotalUrl=t=>`${this.coreApiUrl}/extended/v1/burnchain/rewards/${t}/total`,this.getRewardHoldersUrl=(t,e)=>{let r=`${this.coreApiUrl}/extended/v1/burnchain/reward_slot_holders/${t}`;return e&&(r=`${r}?limit=${e.limit}&offset=${e.offset}`),r},this.getStackerInfoUrl=(t,e)=>`${this.coreApiUrl}${this.readOnlyFunctionCallEndpoint}\n ${t}/${e}/get-stacker-info`,this.coreApiUrl=t.url,this.fetchFn=null!=(e=t.fetchFn)?e:p()}getNameInfo(t){const e=`${this.bnsLookupUrl}/v1/names/${t}`;return this.fetchFn(e).then((t=>{if(404===t.status)throw new Error("Name not found");if(200!==t.status)throw new Error(`Bad response status: ${t.status}`);return t.json()})).then((t=>t.address?Object.assign({},t,{address:t.address}):t))}};let g=A;g.fromName=t=>{switch(t){case"mainnet":return new U;case"testnet":return new T;default:throw new Error(`Invalid network name provided. Must be one of the following: ${E.join(", ")}`)}},g.fromNameOrNetwork=t=>"string"!=typeof t&&"version"in t?t:A.fromName(t);class U extends g{constructor(t){var e;super({url:null!=(e=null==t?void 0:t.url)?e:m,fetchFn:null==t?void 0:t.fetchFn}),this.version=b.Mainnet,this.chainId=y.Mainnet}}class T extends g{constructor(t){var e;super({url:null!=(e=null==t?void 0:t.url)?e:v,fetchFn:null==t?void 0:t.fetchFn}),this.version=b.Testnet,this.chainId=y.Testnet}}class O extends g{constructor(t){var e;super({url:null!=(e=null==t?void 0:t.url)?e:w,fetchFn:null==t?void 0:t.fetchFn}),this.version=b.Testnet,this.chainId=y.Testnet}}})(),n})()));
2
2
  //# sourceMappingURL=index.js.map