gn-provider 1.0.5 → 1.0.7

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/README.md CHANGED
@@ -34,7 +34,7 @@ During installation, the package will automatically:
34
34
  ### Basic Setup
35
35
 
36
36
  ```typescript
37
- import { GNProvider } from 'scrypt-ts';
37
+ import { GNProvider } from 'scrypt-ts/dist/providers/gn-provider';
38
38
  import * as bsv from 'bsv';
39
39
 
40
40
  // Initialize provider (mainnet or testnet)
@@ -1,5 +1,5 @@
1
+ import * as scryptlib from 'scryptlib';
1
2
  import { Provider, TransactionResponse, TxHash, UtxoQueryOptions } from 'scrypt-ts/dist/bsv/abstract-provider';
2
- import * as bsv from 'bsv';
3
3
  import { AddressOption, UTXO } from 'scrypt-ts/dist/bsv/types';
4
4
  declare enum ProviderEvent {
5
5
  Connected = "connected",
@@ -10,13 +10,14 @@ export declare class GNProvider extends Provider {
10
10
  private _network;
11
11
  private _isConnected;
12
12
  private _apiKey;
13
- constructor(network: bsv.Networks.Network, apiKey?: string);
13
+ constructor(network: scryptlib.bsv.Networks.Network, apiKey?: string);
14
+ protected _initializeConnection(): void;
14
15
  get apiPrefix(): string;
15
16
  isConnected(): boolean;
16
17
  connect(): Promise<this>;
17
18
  private _getHeaders;
18
- updateNetwork(network: bsv.Networks.Network): void;
19
- getNetwork(): bsv.Networks.Network;
19
+ updateNetwork(network: scryptlib.bsv.Networks.Network): void;
20
+ getNetwork(): scryptlib.bsv.Networks.Network;
20
21
  protected _ready(): Promise<void>;
21
22
  sendRawTransaction(rawTxHex: string): Promise<TxHash>;
22
23
  listUnspent(address: AddressOption, options?: UtxoQueryOptions): Promise<UTXO[]>;
@@ -46,8 +46,9 @@ exports.GNProvider = void 0;
46
46
  // Agrega esto al inicio del archivo
47
47
  // @ts-ignore
48
48
  const events_1 = require("events");
49
+ const scryptlib = __importStar(require("scryptlib"));
49
50
  const abstract_provider_1 = require("scrypt-ts/dist/bsv/abstract-provider");
50
- const bsv = __importStar(require("bsv"));
51
+ //import * as bsv from 'bsv';
51
52
  //import superagent from 'superagent';
52
53
  const superagent = __importStar(require("superagent"));
53
54
  const utils_1 = require("scrypt-ts/dist/bsv/utils");
@@ -66,8 +67,11 @@ class GNProvider extends abstract_provider_1.Provider {
66
67
  this._apiKey = apiKey;
67
68
  this._initializeConnection();
68
69
  }
70
+ _initializeConnection() {
71
+ this.connect().catch(console.error);
72
+ }
69
73
  get apiPrefix() {
70
- const networkStr = this._network.name === bsv.Networks.mainnet.name ? 'main' : 'test';
74
+ const networkStr = this._network.name === scryptlib.bsv.Networks.mainnet.name ? 'main' : 'test';
71
75
  return `https://api.whatsonchain.com/v1/bsv/${networkStr}`;
72
76
  }
73
77
  isConnected() {
@@ -137,7 +141,7 @@ class GNProvider extends abstract_provider_1.Provider {
137
141
  catch (error) {
138
142
  if ((_a = error.response) === null || _a === void 0 ? void 0 : _a.text) {
139
143
  if (this.needIgnoreError(error.response.text)) {
140
- return new bsv.Transaction(rawTxHex).id;
144
+ return new scryptlib.bsv.Transaction(rawTxHex).id;
141
145
  }
142
146
  throw new Error(`GNProvider ERROR: ${this.friendlyBIP22RejectionMsg(error.response.text)}`);
143
147
  }
@@ -155,7 +159,7 @@ class GNProvider extends abstract_provider_1.Provider {
155
159
  txId: item.tx_hash,
156
160
  outputIndex: item.tx_pos,
157
161
  satoshis: item.value,
158
- script: bsv.Script.buildPublicKeyHashOut(address).toHex(),
162
+ script: scryptlib.bsv.Script.buildPublicKeyHashOut(address).toHex(),
159
163
  }));
160
164
  return options ? (0, utils_1.filterUTXO)(utxos, options) : utxos;
161
165
  });
@@ -189,7 +193,7 @@ class GNProvider extends abstract_provider_1.Provider {
189
193
  const res = yield superagent.get(`${this.apiPrefix}/tx/${txHash}/hex`)
190
194
  .set(headers);
191
195
  if (res.ok) {
192
- return new bsv.Transaction(res.text);
196
+ return new scryptlib.bsv.Transaction(res.text);
193
197
  }
194
198
  throw new Error(`Transaction not found: ${txHash}`);
195
199
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gn-provider",
3
- "version": "1.0.5",
3
+ "version": "1.0.7",
4
4
  "files": [
5
5
  "dist",
6
6
  "scripts",
@@ -25,7 +25,9 @@
25
25
  "description": "This is a BSV blockchain provider for sCrpyt using Whatsonchain API",
26
26
  "dependencies": {
27
27
  "fs-extra": "^11.3.0",
28
- "typescript": "^5.8.3"
28
+ "typescript": "^5.8.3",
29
+ "scryptlib": "^2.2.6",
30
+ "superagent": "^10.2.1"
29
31
  },
30
32
  "devDependencies": {
31
33
  "@types/node": "^24.0.3",