@alephium/web3 0.1.0-rc.3-hc → 0.2.0-rc.1

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 */
@@ -145,6 +148,8 @@ export interface BuildDeployContractTx {
145
148
  gasAmount?: number;
146
149
  /** @format uint256 */
147
150
  gasPrice?: string;
151
+ /** @format block-hash */
152
+ targetBlockHash?: string;
148
153
  }
149
154
  export interface BuildDeployContractTxResult {
150
155
  /** @format int32 */
@@ -173,6 +178,8 @@ export interface BuildExecuteScriptTx {
173
178
  gasAmount?: number;
174
179
  /** @format uint256 */
175
180
  gasPrice?: string;
181
+ /** @format block-hash */
182
+ targetBlockHash?: string;
176
183
  }
177
184
  export interface BuildExecuteScriptTxResult {
178
185
  /** @format int32 */
@@ -221,6 +228,8 @@ export interface BuildSweepAddressTransactions {
221
228
  gasAmount?: number;
222
229
  /** @format uint256 */
223
230
  gasPrice?: string;
231
+ /** @format block-hash */
232
+ targetBlockHash?: string;
224
233
  }
225
234
  export interface BuildSweepAddressTransactionsResult {
226
235
  unsignedTxs: SweepAddressTransaction[];
@@ -238,6 +247,8 @@ export interface BuildTransaction {
238
247
  gasAmount?: number;
239
248
  /** @format uint256 */
240
249
  gasPrice?: string;
250
+ /** @format block-hash */
251
+ targetBlockHash?: string;
241
252
  }
242
253
  export interface BuildTransactionResult {
243
254
  unsignedTx: string;
@@ -447,7 +458,10 @@ export interface InterCliquePeerInfo {
447
458
  /** @format int32 */
448
459
  groupNumPerBroker: number;
449
460
  /** @format inet-socket-address */
450
- address: string;
461
+ address: {
462
+ addr: string;
463
+ port: number;
464
+ };
451
465
  isSynced: boolean;
452
466
  clientVersion: string;
453
467
  }
@@ -468,7 +482,10 @@ export interface NodeInfo {
468
482
  buildInfo: BuildInfo;
469
483
  upnp: boolean;
470
484
  /** @format inet-socket-address */
471
- externalAddress?: string;
485
+ externalAddress?: {
486
+ addr: string;
487
+ port: number;
488
+ };
472
489
  }
473
490
  export interface NodeVersion {
474
491
  version: ReleaseVersion;
@@ -571,6 +588,8 @@ export interface Sweep {
571
588
  gasPrice?: string;
572
589
  /** @format int32 */
573
590
  utxosLimit?: number;
591
+ /** @format block-hash */
592
+ targetBlockHash?: string;
574
593
  }
575
594
  export interface SweepAddressTransaction {
576
595
  /** @format 32-byte-hash */
@@ -836,8 +855,8 @@ export declare class HttpClient<SecurityDataType = unknown> {
836
855
  }
837
856
  /**
838
857
  * @title Alephium API
839
- * @version 1.4.1
840
- * @baseUrl {protocol}://{host}:{port}
858
+ * @version 1.5.0
859
+ * @baseUrl ../
841
860
  */
842
861
  export declare class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDataType> {
843
862
  wallets: {
@@ -28,7 +28,7 @@ var ContentType;
28
28
  })(ContentType = exports.ContentType || (exports.ContentType = {}));
29
29
  class HttpClient {
30
30
  constructor(apiConfig = {}) {
31
- this.baseUrl = '{protocol}://{host}:{port}';
31
+ this.baseUrl = '../';
32
32
  this.securityData = null;
33
33
  this.abortControllers = new Map();
34
34
  this.customFetch = (...fetchParams) => fetch(...fetchParams);
@@ -158,8 +158,8 @@ class HttpClient {
158
158
  exports.HttpClient = HttpClient;
159
159
  /**
160
160
  * @title Alephium API
161
- * @version 1.4.1
162
- * @baseUrl {protocol}://{host}:{port}
161
+ * @version 1.5.0
162
+ * @baseUrl ../
163
163
  */
164
164
  class Api extends HttpClient {
165
165
  constructor() {
@@ -470,6 +470,22 @@ export declare class Api<SecurityDataType extends unknown> extends HttpClient<Se
470
470
  * @request PUT:/utils/sanity-check
471
471
  */
472
472
  putUtilsSanityCheck: (params?: RequestParams) => Promise<void>;
473
+ /**
474
+ * @description Update global log level, accepted: TRACE, DEBUG, INFO, WARN, ERROR
475
+ *
476
+ * @tags Utils
477
+ * @name PutUtilsUpdateGlobalLoglevel
478
+ * @request PUT:/utils/update-global-loglevel
479
+ */
480
+ putUtilsUpdateGlobalLoglevel: (data: 'TRACE' | 'DEBUG' | 'INFO' | 'WARN' | 'ERROR', params?: RequestParams) => Promise<void>;
481
+ /**
482
+ * @description Update logging file, only logback.xml is accepted
483
+ *
484
+ * @tags Utils
485
+ * @name PutUtilsUpdateLogConfig
486
+ * @request PUT:/utils/update-log-config
487
+ */
488
+ putUtilsUpdateLogConfig: (data: string, params?: RequestParams) => Promise<void>;
473
489
  };
474
490
  }
475
491
  export {};
@@ -450,6 +450,32 @@ class Api extends HttpClient {
450
450
  path: `/utils/sanity-check`,
451
451
  method: 'PUT',
452
452
  ...params
453
+ }).then(convertHttpResponse),
454
+ /**
455
+ * @description Update global log level, accepted: TRACE, DEBUG, INFO, WARN, ERROR
456
+ *
457
+ * @tags Utils
458
+ * @name PutUtilsUpdateGlobalLoglevel
459
+ * @request PUT:/utils/update-global-loglevel
460
+ */
461
+ putUtilsUpdateGlobalLoglevel: (data, params = {}) => this.request({
462
+ path: `/utils/update-global-loglevel`,
463
+ method: 'PUT',
464
+ body: data,
465
+ ...params
466
+ }).then(convertHttpResponse),
467
+ /**
468
+ * @description Update logging file, only logback.xml is accepted
469
+ *
470
+ * @tags Utils
471
+ * @name PutUtilsUpdateLogConfig
472
+ * @request PUT:/utils/update-log-config
473
+ */
474
+ putUtilsUpdateLogConfig: (data, params = {}) => this.request({
475
+ path: `/utils/update-log-config`,
476
+ method: 'PUT',
477
+ body: data,
478
+ ...params
453
479
  }).then(convertHttpResponse)
454
480
  };
455
481
  }
@@ -1,6 +1,13 @@
1
1
  import { NodeProvider } from '../api';
2
2
  import { node } from '../api';
3
3
  import { SignDeployContractTxParams, SignExecuteScriptTxParams, SignerWithNodeProvider } from '../signer';
4
+ declare class SourceFile {
5
+ readonly dirs: string[];
6
+ readonly dirPath: string;
7
+ readonly contractPath: string;
8
+ readonly artifactPath: string;
9
+ constructor(dirs: string[], fileName: string);
10
+ }
4
11
  export declare abstract class Common {
5
12
  readonly sourceCodeSha256: string;
6
13
  readonly functions: node.FunctionSig[];
@@ -13,16 +20,15 @@ export declare abstract class Common {
13
20
  protected static _getArtifactFromCache(codeHash: string): Contract | Script | undefined;
14
21
  protected static _putArtifactToCache(contract: Contract): void;
15
22
  constructor(sourceCodeSha256: string, functions: node.FunctionSig[]);
16
- protected static _contractPath(fileName: string): string;
17
- protected static _artifactPath(fileName: string): string;
18
23
  protected static _artifactsFolder(): string;
19
- protected static _handleImports(contractStr: string, importsCache: string[]): Promise<string>;
20
- protected static _loadContractStr(fileName: string, importsCache: string[], validate: (fileName: string) => void): Promise<string>;
24
+ static getSourceFile(path: string, _dirs: string[]): SourceFile;
25
+ protected static _handleImports(pathes: string[], contractStr: string, importsCache: string[]): Promise<string>;
26
+ protected static _loadContractStr(sourceFile: SourceFile, importsCache: string[], validate: (code: string) => void): Promise<string>;
21
27
  static checkFileNameExtension(fileName: string): void;
22
28
  protected static _from<T extends {
23
29
  sourceCodeSha256: string;
24
- }>(provider: NodeProvider, fileName: string, loadContractStr: (fileName: string, importsCache: string[]) => Promise<string>, compile: (provider: NodeProvider, fileName: string, contractStr: string, contractHash: string) => Promise<T>): Promise<T>;
25
- protected _saveToFile(fileName: string): Promise<void>;
30
+ }>(provider: NodeProvider, sourceFile: SourceFile, loadContractStr: (sourceFile: SourceFile, importsCache: string[]) => Promise<string>, compile: (provider: NodeProvider, sourceFile: SourceFile, contractStr: string, contractHash: string) => Promise<T>): Promise<T>;
31
+ protected _saveToFile(sourceFile: SourceFile): Promise<void>;
26
32
  abstract buildByteCodeToDeploy(initialFields?: Fields): string;
27
33
  }
28
34
  export declare class Contract extends Common {
@@ -33,10 +39,11 @@ export declare class Contract extends Common {
33
39
  constructor(sourceCodeSha256: string, bytecode: string, codeHash: string, fieldsSig: node.FieldsSig, eventsSig: node.EventSig[], functions: node.FunctionSig[]);
34
40
  static checkCodeType(fileName: string, contractStr: string): void;
35
41
  private static loadContractStr;
36
- static fromSource(provider: NodeProvider, fileName: string): Promise<Contract>;
42
+ static fromSource(provider: NodeProvider, path: string): Promise<Contract>;
37
43
  private static compile;
38
44
  static fromJson(artifact: any): Contract;
39
- static fromArtifactFile(fileName: string): Promise<Contract>;
45
+ static fromArtifactFile(path: string): Promise<Contract>;
46
+ fetchState(provider: NodeProvider, address: string, group: number): Promise<ContractState>;
40
47
  toString(): string;
41
48
  toState(fields: Fields, asset: Asset, address?: string): ContractState;
42
49
  static randomAddress(): string;
@@ -65,10 +72,10 @@ export declare class Script extends Common {
65
72
  constructor(sourceCodeSha256: string, bytecodeTemplate: string, fieldsSig: node.FieldsSig, functions: node.FunctionSig[]);
66
73
  static checkCodeType(fileName: string, contractStr: string): void;
67
74
  private static loadContractStr;
68
- static fromSource(provider: NodeProvider, fileName: string): Promise<Script>;
75
+ static fromSource(provider: NodeProvider, path: string): Promise<Script>;
69
76
  private static compile;
70
77
  static fromJson(artifact: any): Script;
71
- static fromArtifactFile(fileName: string): Promise<Script>;
78
+ static fromArtifactFile(path: string): Promise<Script>;
72
79
  toString(): string;
73
80
  paramsForDeployment(params: BuildExecuteScriptTx): Promise<SignExecuteScriptTxParams>;
74
81
  transactionForDeployment(signer: SignerWithNodeProvider, params: Omit<BuildExecuteScriptTx, 'signerAddress'>): Promise<BuildScriptTxResult>;
@@ -180,3 +187,4 @@ export interface BuildScriptTxResult {
180
187
  unsignedTx: string;
181
188
  txId: string;
182
189
  }
190
+ export {};
@@ -47,6 +47,20 @@ const fs_1 = __importDefault(require("fs"));
47
47
  const fs_2 = require("fs");
48
48
  const ralph = __importStar(require("./ralph"));
49
49
  const utils_1 = require("../utils");
50
+ class SourceFile {
51
+ constructor(dirs, fileName) {
52
+ this.dirs = dirs;
53
+ this.dirPath = dirs.length === 0 ? '' : dirs.join('/') + '/';
54
+ if (fileName.endsWith('.json')) {
55
+ this.contractPath = './contracts/' + this.dirPath + fileName.slice(0, -5);
56
+ this.artifactPath = './artifacts/' + this.dirPath + fileName;
57
+ }
58
+ else {
59
+ this.contractPath = './contracts/' + this.dirPath + fileName;
60
+ this.artifactPath = './artifacts/' + this.dirPath + fileName + '.json';
61
+ }
62
+ }
63
+ }
50
64
  class Common {
51
65
  constructor(sourceCodeSha256, functions) {
52
66
  this.sourceCodeSha256 = sourceCodeSha256;
@@ -64,73 +78,86 @@ class Common {
64
78
  this._artifactCache.set(contract.codeHash, contract);
65
79
  }
66
80
  }
67
- static _contractPath(fileName) {
68
- if (fileName.endsWith('.json')) {
69
- return `./contracts/${fileName.slice(0, -5)}`;
70
- }
71
- else {
72
- return `./contracts/${fileName}`;
73
- }
74
- }
75
- static _artifactPath(fileName) {
76
- if (fileName.endsWith('.json')) {
77
- return `./artifacts/${fileName}`;
78
- }
79
- else {
80
- return `./artifacts/${fileName}.json`;
81
- }
82
- }
83
81
  static _artifactsFolder() {
84
82
  return './artifacts/';
85
83
  }
86
- static async _handleImports(contractStr, importsCache) {
84
+ static getSourceFile(path, _dirs) {
85
+ const parts = path.split('/');
86
+ const dirs = Array.from(_dirs);
87
+ if (parts.length === 1) {
88
+ return new SourceFile(dirs, path);
89
+ }
90
+ parts.slice(0, parts.length - 1).forEach((part) => {
91
+ switch (part) {
92
+ case '.': {
93
+ break;
94
+ }
95
+ case '..': {
96
+ if (dirs.length === 0) {
97
+ throw new Error('Invalid file path: ' + path);
98
+ }
99
+ dirs.pop();
100
+ break;
101
+ }
102
+ default: {
103
+ dirs.push(part);
104
+ }
105
+ }
106
+ });
107
+ return new SourceFile(dirs, parts[parts.length - 1]);
108
+ }
109
+ static async _handleImports(pathes, contractStr, importsCache) {
87
110
  const localImportsCache = [];
88
111
  let result = contractStr.replace(Common.importRegex, (match) => {
89
112
  localImportsCache.push(match);
90
113
  return '';
91
114
  });
92
115
  for (const myImport of localImportsCache) {
93
- const fileName = myImport.slice(8, -1);
94
- if (!importsCache.includes(fileName)) {
95
- importsCache.push(fileName);
96
- const importContractStr = await Common._loadContractStr(fileName, importsCache, (code) => Contract.checkCodeType(fileName, code));
116
+ const relativePath = myImport.slice(8, -1);
117
+ const importSourceFile = this.getSourceFile(relativePath, pathes);
118
+ if (!importsCache.includes(importSourceFile.contractPath)) {
119
+ importsCache.push(importSourceFile.contractPath);
120
+ const importContractStr = await Common._loadContractStr(importSourceFile, importsCache, (code) => Contract.checkCodeType(importSourceFile.contractPath, code));
97
121
  result = result.concat('\n', importContractStr);
98
122
  }
99
123
  }
100
124
  return result;
101
125
  }
102
- static async _loadContractStr(fileName, importsCache, validate) {
103
- const contractPath = this._contractPath(fileName);
126
+ static async _loadContractStr(sourceFile, importsCache, validate) {
127
+ const contractPath = sourceFile.contractPath;
104
128
  const contractBuffer = await fs_2.promises.readFile(contractPath);
105
129
  const contractStr = contractBuffer.toString();
106
130
  validate(contractStr);
107
- return Common._handleImports(contractStr, importsCache);
131
+ return Common._handleImports(sourceFile.dirs, contractStr, importsCache);
108
132
  }
109
133
  static checkFileNameExtension(fileName) {
110
134
  if (!fileName.endsWith('.ral')) {
111
135
  throw new Error('Smart contract file name should end with ".ral"');
112
136
  }
113
137
  }
114
- static async _from(provider, fileName, loadContractStr, compile) {
115
- Common.checkFileNameExtension(fileName);
116
- const contractStr = await loadContractStr(fileName, []);
138
+ static async _from(provider, sourceFile, loadContractStr, compile) {
139
+ Common.checkFileNameExtension(sourceFile.contractPath);
140
+ const contractStr = await loadContractStr(sourceFile, []);
117
141
  const contractHash = cryptojs.SHA256(contractStr).toString();
118
142
  const existingContract = this._getArtifactFromCache(contractHash);
119
143
  if (typeof existingContract !== 'undefined') {
120
144
  return existingContract;
121
145
  }
122
146
  else {
123
- return compile(provider, fileName, contractStr, contractHash);
147
+ return compile(provider, sourceFile, contractStr, contractHash);
124
148
  }
125
149
  }
126
- _saveToFile(fileName) {
127
- const artifactPath = Common._artifactPath(fileName);
128
- return fs_2.promises.writeFile(artifactPath, this.toString());
150
+ _saveToFile(sourceFile) {
151
+ const folder = Common._artifactsFolder() + sourceFile.dirPath;
152
+ if (!fs_1.default.existsSync(folder)) {
153
+ fs_1.default.mkdirSync(folder, { recursive: true });
154
+ }
155
+ return fs_2.promises.writeFile(sourceFile.artifactPath, this.toString());
129
156
  }
130
157
  }
131
158
  exports.Common = Common;
132
- Common.importRegex = new RegExp('^import "[a-z][a-z_0-9]*.ral"', 'mg');
133
- Common.contractRegex = new RegExp('^TxContract [A-Z][a-zA-Z0-9]*', 'mg');
159
+ Common.importRegex = new RegExp('^import "([^"/]+/(([^"]+)/)?)?[a-z][a-z_0-9]*.ral"', 'mg');
160
+ Common.contractRegex = new RegExp('^(Abstract[ ]+)?Contract [A-Z][a-zA-Z0-9]*', 'mg');
134
161
  Common.interfaceRegex = new RegExp('^Interface [A-Z][a-zA-Z0-9]* \\{', 'mg');
135
162
  Common.scriptRegex = new RegExp('^TxScript [A-Z][a-zA-Z0-9]*', 'mg');
136
163
  Common._artifactCache = new Map();
@@ -145,35 +172,40 @@ class Contract extends Common {
145
172
  }
146
173
  static checkCodeType(fileName, contractStr) {
147
174
  const interfaceMatches = contractStr.match(Contract.interfaceRegex);
148
- if (interfaceMatches) {
149
- return;
150
- }
151
175
  const contractMatches = contractStr.match(Contract.contractRegex);
152
- if (contractMatches === null) {
176
+ if (interfaceMatches === null && contractMatches === null) {
153
177
  throw new Error(`No contract found in: ${fileName}`);
154
178
  }
155
- else if (contractMatches.length > 1) {
156
- throw new Error(`Multiple contracts in: ${fileName}`);
179
+ if (interfaceMatches && contractMatches) {
180
+ throw new Error(`Multiple contracts and interfaces in: ${fileName}`);
157
181
  }
158
- else {
159
- return;
182
+ if (interfaceMatches === null) {
183
+ if (contractMatches !== null && contractMatches.length > 1) {
184
+ throw new Error(`Multiple contracts in: ${fileName}`);
185
+ }
186
+ }
187
+ if (contractMatches === null) {
188
+ if (interfaceMatches !== null && interfaceMatches.length > 1) {
189
+ throw new Error(`Multiple interfaces in: ${fileName}`);
190
+ }
160
191
  }
161
192
  }
162
- static async loadContractStr(fileName, importsCache) {
163
- return Common._loadContractStr(fileName, importsCache, (code) => Contract.checkCodeType(fileName, code));
193
+ static async loadContractStr(sourceFile) {
194
+ return Common._loadContractStr(sourceFile, [], (code) => Contract.checkCodeType(sourceFile.contractPath, code));
164
195
  }
165
- static async fromSource(provider, fileName) {
196
+ static async fromSource(provider, path) {
166
197
  if (!fs_1.default.existsSync(Common._artifactsFolder())) {
167
198
  fs_1.default.mkdirSync(Common._artifactsFolder(), { recursive: true });
168
199
  }
169
- const contract = await Common._from(provider, fileName, (fileName, importCaches) => Contract.loadContractStr(fileName, importCaches), Contract.compile);
200
+ const sourceFile = this.getSourceFile(path, []);
201
+ const contract = await Common._from(provider, sourceFile, (sourceFile) => Contract.loadContractStr(sourceFile), Contract.compile);
170
202
  this._putArtifactToCache(contract);
171
203
  return contract;
172
204
  }
173
- static async compile(provider, fileName, contractStr, contractHash) {
205
+ static async compile(provider, sourceFile, contractStr, contractHash) {
174
206
  const compiled = await provider.contracts.postContractsCompileContract({ code: contractStr });
175
207
  const artifact = new Contract(contractHash, compiled.bytecode, compiled.codeHash, compiled.fields, compiled.events, compiled.functions);
176
- await artifact._saveToFile(fileName);
208
+ await artifact._saveToFile(sourceFile);
177
209
  return artifact;
178
210
  }
179
211
  // TODO: safely parse json
@@ -191,12 +223,17 @@ class Contract extends Common {
191
223
  return contract;
192
224
  }
193
225
  // support both 'code.ral' and 'code.ral.json'
194
- static async fromArtifactFile(fileName) {
195
- const artifactPath = Contract._artifactPath(fileName);
226
+ static async fromArtifactFile(path) {
227
+ const sourceFile = this.getSourceFile(path, []);
228
+ const artifactPath = sourceFile.artifactPath;
196
229
  const content = await fs_2.promises.readFile(artifactPath);
197
230
  const artifact = JSON.parse(content.toString());
198
231
  return Contract.fromJson(artifact);
199
232
  }
233
+ async fetchState(provider, address, group) {
234
+ const state = await provider.contracts.getContractsAddressState(address, { group: group });
235
+ return this.fromApiContractState(state);
236
+ }
200
237
  toString() {
201
238
  return JSON.stringify({
202
239
  sourceCodeSha256: this.sourceCodeSha256,
@@ -415,16 +452,17 @@ class Script extends Common {
415
452
  return;
416
453
  }
417
454
  }
418
- static async loadContractStr(fileName, importsCache) {
419
- return Common._loadContractStr(fileName, importsCache, (code) => Script.checkCodeType(fileName, code));
455
+ static async loadContractStr(sourceFile) {
456
+ return Common._loadContractStr(sourceFile, [], (code) => Script.checkCodeType(sourceFile.contractPath, code));
420
457
  }
421
- static async fromSource(provider, fileName) {
422
- return Common._from(provider, fileName, (fileName, importsCache) => Script.loadContractStr(fileName, importsCache), Script.compile);
458
+ static async fromSource(provider, path) {
459
+ const sourceFile = this.getSourceFile(path, []);
460
+ return Common._from(provider, sourceFile, (sourceFile) => Script.loadContractStr(sourceFile), Script.compile);
423
461
  }
424
- static async compile(provider, fileName, scriptStr, contractHash) {
462
+ static async compile(provider, sourceFile, scriptStr, contractHash) {
425
463
  const compiled = await provider.contracts.postContractsCompileScript({ code: scriptStr });
426
464
  const artifact = new Script(contractHash, compiled.bytecodeTemplate, compiled.fields, compiled.functions);
427
- await artifact._saveToFile(fileName);
465
+ await artifact._saveToFile(sourceFile);
428
466
  return artifact;
429
467
  }
430
468
  // TODO: safely parse json
@@ -437,8 +475,9 @@ class Script extends Common {
437
475
  }
438
476
  return new Script(artifact.sourceCodeSha256, artifact.bytecodeTemplate, artifact.fieldsSig, artifact.functions);
439
477
  }
440
- static async fromArtifactFile(fileName) {
441
- const artifactPath = Common._artifactPath(fileName);
478
+ static async fromArtifactFile(path) {
479
+ const sourceFile = this.getSourceFile(path, []);
480
+ const artifactPath = sourceFile.artifactPath;
442
481
  const content = await fs_2.promises.readFile(artifactPath);
443
482
  const artifact = JSON.parse(content.toString());
444
483
  return this.fromJson(artifact);
@@ -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"));
@@ -182,7 +182,7 @@ function contractIdFromTx(txId, outputIndex) {
182
182
  }
183
183
  exports.contractIdFromTx = contractIdFromTx;
184
184
  function subContractId(parentContractId, pathInHex) {
185
- const data = buffer_1.Buffer.concat([hexToBinUnsafe(pathInHex), hexToBinUnsafe(parentContractId)]);
185
+ const data = buffer_1.Buffer.concat([hexToBinUnsafe(parentContractId), hexToBinUnsafe(pathInHex)]);
186
186
  return binToHex(blakejs_1.default.blake2b(blakejs_1.default.blake2b(data, undefined, 32), undefined, 32));
187
187
  }
188
188
  exports.subContractId = subContractId;
@@ -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.1.0-rc.3-hc",
3
+ "version": "0.2.0-rc.1",
4
4
  "description": "A JS/TS library to interact with the Alephium platform",
5
5
  "license": "GPL",
6
6
  "main": "dist/src/index.js",
@@ -27,14 +27,14 @@
27
27
  },
28
28
  "author": "Alephium dev <dev@alephium.org>",
29
29
  "config": {
30
- "alephium_version": "token-balance",
31
- "explorer_backend_version": "1.7.0"
30
+ "alephium_version": "1.5.0-rc2",
31
+ "explorer_backend_version": "1.7.1"
32
32
  },
33
33
  "scripts": {
34
34
  "build": "rm -rf dist/* && npx tsc --build . && webpack",
35
35
  "bundle": "webpack",
36
36
  "update-schemas": "npm run update-schema:alephium && npm run update-schema:explorer",
37
- "update-schema:alephium": "npx swagger-typescript-api -t ./configs -o ./src/api -n api-alephium.ts -p https://raw.githubusercontent.com/alephium/alephium/${npm_package_config_alephium_version}/api/src/main/resources/openapi.json",
37
+ "update-schema:alephium": "npx swagger-typescript-api -t ./configs -o ./src/api -n api-alephium.ts -p https://raw.githubusercontent.com/alephium/alephium/v${npm_package_config_alephium_version}/api/src/main/resources/openapi.json",
38
38
  "update-schema:explorer": "npx swagger-typescript-api -t ./configs -o ./src/api -n api-explorer.ts -p https://raw.githubusercontent.com/alephium/explorer-backend/v${npm_package_config_explorer_backend_version}/app/src/main/resources/explorer-backend-openapi.json",
39
39
  "check-versions": "node scripts/check-versions.js ${npm_package_config_alephium_version} ${npm_package_config_explorer_backend_version}",
40
40
  "dev": "tsnd --respawn lib/index.ts",
@@ -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 {
@@ -207,6 +207,9 @@ export interface BuildDeployContractTx {
207
207
 
208
208
  /** @format uint256 */
209
209
  gasPrice?: string
210
+
211
+ /** @format block-hash */
212
+ targetBlockHash?: string
210
213
  }
211
214
 
212
215
  export interface BuildDeployContractTxResult {
@@ -246,6 +249,9 @@ export interface BuildExecuteScriptTx {
246
249
 
247
250
  /** @format uint256 */
248
251
  gasPrice?: string
252
+
253
+ /** @format block-hash */
254
+ targetBlockHash?: string
249
255
  }
250
256
 
251
257
  export interface BuildExecuteScriptTxResult {
@@ -311,6 +317,9 @@ export interface BuildSweepAddressTransactions {
311
317
 
312
318
  /** @format uint256 */
313
319
  gasPrice?: string
320
+
321
+ /** @format block-hash */
322
+ targetBlockHash?: string
314
323
  }
315
324
 
316
325
  export interface BuildSweepAddressTransactionsResult {
@@ -334,6 +343,9 @@ export interface BuildTransaction {
334
343
 
335
344
  /** @format uint256 */
336
345
  gasPrice?: string
346
+
347
+ /** @format block-hash */
348
+ targetBlockHash?: string
337
349
  }
338
350
 
339
351
  export interface BuildTransactionResult {
@@ -613,7 +625,7 @@ export interface InterCliquePeerInfo {
613
625
  groupNumPerBroker: number
614
626
 
615
627
  /** @format inet-socket-address */
616
- address: string
628
+ address: { addr: string; port: number }
617
629
  isSynced: boolean
618
630
  clientVersion: string
619
631
  }
@@ -641,7 +653,7 @@ export interface NodeInfo {
641
653
  upnp: boolean
642
654
 
643
655
  /** @format inet-socket-address */
644
- externalAddress?: string
656
+ externalAddress?: { addr: string; port: number }
645
657
  }
646
658
 
647
659
  export interface NodeVersion {
@@ -778,6 +790,9 @@ export interface Sweep {
778
790
 
779
791
  /** @format int32 */
780
792
  utxosLimit?: number
793
+
794
+ /** @format block-hash */
795
+ targetBlockHash?: string
781
796
  }
782
797
 
783
798
  export interface SweepAddressTransaction {
@@ -1099,7 +1114,7 @@ export enum ContentType {
1099
1114
  }
1100
1115
 
1101
1116
  export class HttpClient<SecurityDataType = unknown> {
1102
- public baseUrl: string = '{protocol}://{host}:{port}'
1117
+ public baseUrl: string = '../'
1103
1118
  private securityData: SecurityDataType | null = null
1104
1119
  private securityWorker?: ApiConfig<SecurityDataType>['securityWorker']
1105
1120
  private abortControllers = new Map<CancelToken, AbortController>()
@@ -1264,8 +1279,8 @@ export class HttpClient<SecurityDataType = unknown> {
1264
1279
 
1265
1280
  /**
1266
1281
  * @title Alephium API
1267
- * @version 1.4.1
1268
- * @baseUrl {protocol}://{host}:{port}
1282
+ * @version 1.5.0
1283
+ * @baseUrl ../
1269
1284
  */
1270
1285
  export class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDataType> {
1271
1286
  wallets = {