@alephium/web3 0.0.1-test.0 → 0.0.1-test.2

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.
@@ -129,7 +129,10 @@ export interface BrokerInfo {
129
129
  /** @format int32 */
130
130
  brokerNum: number;
131
131
  /** @format inet-socket-address */
132
- address: string;
132
+ address: {
133
+ addr: string;
134
+ port: number;
135
+ };
133
136
  }
134
137
  export interface BuildDeployContractTx {
135
138
  /** @format public-key */
@@ -447,7 +450,10 @@ export interface InterCliquePeerInfo {
447
450
  /** @format int32 */
448
451
  groupNumPerBroker: number;
449
452
  /** @format inet-socket-address */
450
- address: string;
453
+ address: {
454
+ addr: string;
455
+ port: number;
456
+ };
451
457
  isSynced: boolean;
452
458
  clientVersion: string;
453
459
  }
@@ -468,7 +474,10 @@ export interface NodeInfo {
468
474
  buildInfo: BuildInfo;
469
475
  upnp: boolean;
470
476
  /** @format inet-socket-address */
471
- externalAddress?: string;
477
+ externalAddress?: {
478
+ addr: string;
479
+ port: number;
480
+ };
472
481
  }
473
482
  export interface NodeVersion {
474
483
  version: ReleaseVersion;
@@ -836,7 +845,7 @@ export declare class HttpClient<SecurityDataType = unknown> {
836
845
  }
837
846
  /**
838
847
  * @title Alephium API
839
- * @version 1.4.1
848
+ * @version 1.4.2
840
849
  * @baseUrl {protocol}://{host}:{port}
841
850
  */
842
851
  export declare class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDataType> {
@@ -158,7 +158,7 @@ class HttpClient {
158
158
  exports.HttpClient = HttpClient;
159
159
  /**
160
160
  * @title Alephium API
161
- * @version 1.4.1
161
+ * @version 1.4.2
162
162
  * @baseUrl {protocol}://{host}:{port}
163
163
  */
164
164
  class Api extends HttpClient {
@@ -20,6 +20,8 @@ export declare function addressFromContractId(contractId: string): string;
20
20
  export declare function contractIdFromTx(txId: string, outputIndex: number): string;
21
21
  export declare function subContractId(parentContractId: string, pathInHex: string): string;
22
22
  export declare function stringToHex(str: string): string;
23
+ export declare function hexToString(str: any): string;
24
+ export declare function timeout(ms: number): Promise<unknown>;
23
25
  declare type _Eq<X, Y> = (<T>() => T extends X ? 1 : 2) extends <T>() => T extends Y ? 1 : 2 ? true : false;
24
26
  export declare type Eq<X, Y> = _Eq<{
25
27
  [P in keyof X]: X[P];
@@ -20,7 +20,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
20
20
  return (mod && mod.__esModule) ? mod : { "default": mod };
21
21
  };
22
22
  Object.defineProperty(exports, "__esModule", { value: true });
23
- exports.assertType = exports.stringToHex = exports.subContractId = exports.contractIdFromTx = exports.addressFromContractId = exports.addressFromPublicKey = exports.publicKeyFromPrivateKey = exports.binToHex = exports.hexToBinUnsafe = exports.tokenIdFromAddress = exports.contractIdFromAddress = exports.groupOfAddress = exports.isHexString = exports.signatureDecode = exports.signatureEncode = exports.convertHttpResponse = void 0;
23
+ exports.assertType = exports.timeout = exports.hexToString = exports.stringToHex = exports.subContractId = exports.contractIdFromTx = exports.addressFromContractId = exports.addressFromPublicKey = exports.publicKeyFromPrivateKey = exports.binToHex = exports.hexToBinUnsafe = exports.tokenIdFromAddress = exports.contractIdFromAddress = exports.groupOfAddress = exports.isHexString = exports.signatureDecode = exports.signatureEncode = exports.convertHttpResponse = void 0;
24
24
  const elliptic_1 = require("elliptic");
25
25
  const bn_js_1 = __importDefault(require("bn.js"));
26
26
  const blakejs_1 = __importDefault(require("blakejs"));
@@ -194,6 +194,14 @@ function stringToHex(str) {
194
194
  return hex;
195
195
  }
196
196
  exports.stringToHex = stringToHex;
197
+ function hexToString(str) {
198
+ return buffer_1.Buffer.from(str.toString(), 'hex').toString();
199
+ }
200
+ exports.hexToString = hexToString;
201
+ function timeout(ms) {
202
+ return new Promise((resolve) => setTimeout(resolve, ms));
203
+ }
204
+ exports.timeout = timeout;
197
205
  // eslint-disable-next-line @typescript-eslint/no-empty-function, @typescript-eslint/no-unused-vars
198
206
  function assertType() { }
199
207
  exports.assertType = assertType;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alephium/web3",
3
- "version": "0.0.1-test.0",
3
+ "version": "0.0.1-test.2",
4
4
  "description": "A JS/TS library to interact with the Alephium platform",
5
5
  "license": "GPL",
6
6
  "main": "dist/src/index.js",
@@ -185,7 +185,7 @@ export interface BrokerInfo {
185
185
  brokerNum: number
186
186
 
187
187
  /** @format inet-socket-address */
188
- address: string
188
+ address: { addr: string; port: number }
189
189
  }
190
190
 
191
191
  export interface BuildDeployContractTx {
@@ -613,7 +613,7 @@ export interface InterCliquePeerInfo {
613
613
  groupNumPerBroker: number
614
614
 
615
615
  /** @format inet-socket-address */
616
- address: string
616
+ address: { addr: string; port: number }
617
617
  isSynced: boolean
618
618
  clientVersion: string
619
619
  }
@@ -641,7 +641,7 @@ export interface NodeInfo {
641
641
  upnp: boolean
642
642
 
643
643
  /** @format inet-socket-address */
644
- externalAddress?: string
644
+ externalAddress?: { addr: string; port: number }
645
645
  }
646
646
 
647
647
  export interface NodeVersion {
@@ -1264,7 +1264,7 @@ export class HttpClient<SecurityDataType = unknown> {
1264
1264
 
1265
1265
  /**
1266
1266
  * @title Alephium API
1267
- * @version 1.4.1
1267
+ * @version 1.4.2
1268
1268
  * @baseUrl {protocol}://{host}:{port}
1269
1269
  */
1270
1270
  export class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDataType> {
@@ -154,7 +154,8 @@ describe('utils', function () {
154
154
  ).toBe('293c948c81c5a9495178fff8b8c9f29f4f3e09e1728c40e9253c87adf5e18770')
155
155
  })
156
156
 
157
- it('should convert from string to hex', () => {
157
+ it('should convert from string to hex and back', () => {
158
158
  expect(utils.stringToHex('Hello Alephium!')).toBe('48656c6c6f20416c65706869756d21')
159
+ expect(utils.hexToString('48656c6c6f20416c65706869756d21')).toBe('Hello Alephium!')
159
160
  })
160
161
  })
@@ -203,6 +203,14 @@ export function stringToHex(str: string): string {
203
203
  return hex
204
204
  }
205
205
 
206
+ export function hexToString(str: any): string {
207
+ return Buffer.from(str.toString(), 'hex').toString()
208
+ }
209
+
210
+ export function timeout(ms: number) {
211
+ return new Promise((resolve) => setTimeout(resolve, ms))
212
+ }
213
+
206
214
  type _Eq<X, Y> = (<T>() => T extends X ? 1 : 2) extends <T>() => T extends Y ? 1 : 2 ? true : false
207
215
  export type Eq<X, Y> = _Eq<{ [P in keyof X]: X[P] }, { [P in keyof Y]: Y[P] }>
208
216
  // eslint-disable-next-line @typescript-eslint/no-empty-function, @typescript-eslint/no-unused-vars
@@ -22,7 +22,7 @@ import { Contract, Script } from '../src/contract'
22
22
  import { NodeWallet, SignExecuteScriptTxParams } from '../src/signer'
23
23
  import { ContractEvent } from '../src/api/api-alephium'
24
24
  import { testWallet } from '../src/test'
25
- import { SubscribeOptions } from '../src/utils'
25
+ import { SubscribeOptions, timeout } from '../src/utils'
26
26
 
27
27
  describe('events', function () {
28
28
  async function deployContract(provider: NodeProvider, signer: NodeWallet): Promise<[string, string]> {
@@ -78,7 +78,7 @@ describe('events', function () {
78
78
  signerAddress: (await signer.getAccounts())[0].address
79
79
  })
80
80
  await executeScript(scriptTxParams, signer, 3)
81
- await new Promise((resolve) => setTimeout(resolve, 3000))
81
+ await timeout(3000)
82
82
 
83
83
  expect(events.length).toEqual(3)
84
84
  events.forEach((event) => {
@@ -117,7 +117,7 @@ describe('events', function () {
117
117
  initialFields: { addContractId: contractId }
118
118
  })
119
119
  await signer.submitTransaction(scriptTx0.unsignedTx, scriptTx0.txId)
120
- await new Promise((resolve) => setTimeout(resolve, 1500))
120
+ await timeout(1500)
121
121
  subscription.unsubscribe()
122
122
 
123
123
  expect(events.length).toEqual(1)
@@ -132,7 +132,7 @@ describe('events', function () {
132
132
  initialFields: { addContractId: contractId }
133
133
  })
134
134
  await signer.submitTransaction(scriptTx1.unsignedTx, scriptTx1.txId)
135
- await new Promise((resolve) => setTimeout(resolve, 1500))
135
+ await timeout(1500)
136
136
  expect(events.length).toEqual(1)
137
137
  })
138
138
  })
@@ -21,7 +21,7 @@ import { subscribeToTxStatus } from '../src/transaction/status'
21
21
  import { Contract } from '../src/contract'
22
22
  import { TxStatus } from '../src/api/api-alephium'
23
23
  import { testWallet } from '../src/test'
24
- import { SubscribeOptions } from '../src/utils'
24
+ import { SubscribeOptions, timeout } from '../src/utils'
25
25
 
26
26
  describe('transactions', function () {
27
27
  it('should subscribe transaction status', async () => {
@@ -53,11 +53,11 @@ describe('transactions', function () {
53
53
  const counterBeforeSubscribe = counter
54
54
 
55
55
  const subscription = subscribeToTxStatus(subscriptOptions, subDeployTx.txId)
56
- await new Promise((resolve) => setTimeout(resolve, 1500))
56
+ await timeout(1500)
57
57
  expect(txStatus).toMatchObject({ type: 'TxNotFound' })
58
58
 
59
59
  const subSubmitResult = await signer.submitTransaction(subDeployTx.unsignedTx, subDeployTx.txId)
60
- await new Promise((resolve) => setTimeout(resolve, 1500))
60
+ await timeout(1500)
61
61
  expect(txStatus).toMatchObject({ type: 'Confirmed' })
62
62
 
63
63
  expect(counterBeforeSubscribe).toBeLessThan(counter)
@@ -65,8 +65,8 @@ describe('transactions', function () {
65
65
  subscription.unsubscribe()
66
66
 
67
67
  const counterAfterUnsubscribe = counter
68
- await new Promise((resolve) => setTimeout(resolve, 1500))
68
+ await timeout(1500)
69
69
  expect(txStatus).toMatchObject({ type: 'Confirmed' })
70
70
  expect(counterAfterUnsubscribe).toEqual(counter)
71
- })
71
+ }, 10000)
72
72
  })