@alephium/web3 0.2.0-rc.19 → 0.2.0-rc.20

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.
@@ -1,4 +1,4 @@
1
- import { NamedVals, node, NodeProvider, Number256, Token, Val } from '../api';
1
+ import { NamedVals, node, Number256, Token, Val } from '../api';
2
2
  import { SignDeployContractTxParams, SignExecuteScriptTxParams, SignerWithNodeProvider } from '../signer';
3
3
  export declare type FieldsSig = node.FieldsSig;
4
4
  export declare type EventSig = node.EventSig;
@@ -60,7 +60,6 @@ export declare class Project {
60
60
  projectArtifact: ProjectArtifact;
61
61
  readonly contractsRootDir: string;
62
62
  readonly artifactsRootDir: string;
63
- readonly nodeProvider: NodeProvider;
64
63
  static currentProject: Project;
65
64
  static readonly abstractContractMatcher: TypedMatcher<SourceType>;
66
65
  static readonly contractMatcher: TypedMatcher<SourceType.Contract>;
@@ -181,7 +180,6 @@ export interface ContractEventByTxId {
181
180
  }
182
181
  export declare type DebugMessage = node.DebugMessage;
183
182
  export interface TestContractResult {
184
- address: string;
185
183
  contractId: string;
186
184
  contractAddress: string;
187
185
  returns: Val[];
@@ -52,6 +52,7 @@ const api_1 = require("../api");
52
52
  const ralph = __importStar(require("./ralph"));
53
53
  const utils_1 = require("../utils");
54
54
  const global_1 = require("../global");
55
+ const __1 = require("..");
55
56
  var SourceType;
56
57
  (function (SourceType) {
57
58
  SourceType[SourceType["Contract"] = 0] = "Contract";
@@ -155,8 +156,7 @@ class ProjectArtifact {
155
156
  }
156
157
  ProjectArtifact.artifactFileName = '.project.json';
157
158
  class Project {
158
- constructor(provider, contractsRootDir, artifactsRootDir, sourceFiles, contracts, scripts, errorOnWarnings, projectArtifact) {
159
- this.nodeProvider = provider;
159
+ constructor(contractsRootDir, artifactsRootDir, sourceFiles, contracts, scripts, errorOnWarnings, projectArtifact) {
160
160
  this.contractsRootDir = contractsRootDir;
161
161
  this.artifactsRootDir = artifactsRootDir;
162
162
  this.sourceFiles = sourceFiles;
@@ -274,7 +274,7 @@ class Project {
274
274
  scripts.push(new Compiled(sourceFile, script, scriptResult.warnings));
275
275
  });
276
276
  const projectArtifact = Project.buildProjectArtifact(files, contracts, scripts, compilerOptions);
277
- const project = new Project(provider, contractsRootDir, artifactsRootDir, files, contracts, scripts, errorOnWarnings, projectArtifact);
277
+ const project = new Project(contractsRootDir, artifactsRootDir, files, contracts, scripts, errorOnWarnings, projectArtifact);
278
278
  await project.saveArtifactsToFile();
279
279
  return project;
280
280
  }
@@ -298,7 +298,7 @@ class Project {
298
298
  scripts.push(new Compiled(file, artifact, warnings));
299
299
  }
300
300
  }
301
- return new Project(provider, contractsRootDir, artifactsRootDir, files, contracts, scripts, errorOnWarnings, projectArtifact);
301
+ return new Project(contractsRootDir, artifactsRootDir, files, contracts, scripts, errorOnWarnings, projectArtifact);
302
302
  }
303
303
  catch (error) {
304
304
  console.log(`Failed to load artifacts, error: ${error}, try to re-compile contracts...`);
@@ -424,7 +424,7 @@ class Contract extends Artifact {
424
424
  return Contract.fromJson(artifact, bytecodeDebugPatch, codeHashDebug);
425
425
  }
426
426
  async fetchState(address, group) {
427
- const state = await Project.currentProject.nodeProvider.contracts.getContractsAddressState(address, {
427
+ const state = await __1.web3.getCurrentNodeProvider().contracts.getContractsAddressState(address, {
428
428
  group: group
429
429
  });
430
430
  return this.fromApiContractState(state);
@@ -467,7 +467,7 @@ class Contract extends Artifact {
467
467
  }
468
468
  async _test(funcName, params, expectPublic, accessType, printDebugMessages) {
469
469
  const apiParams = this.toTestContract(funcName, params);
470
- const apiResult = await Project.currentProject.nodeProvider.contracts.postContractsTestContract(apiParams);
470
+ const apiResult = await __1.web3.getCurrentNodeProvider().contracts.postContractsTestContract(apiParams);
471
471
  const methodIndex = typeof params.testMethodIndex !== 'undefined' ? params.testMethodIndex : this.getMethodIndex(funcName);
472
472
  const isPublic = this.functions[`${methodIndex}`].isPublic;
473
473
  if (printDebugMessages) {
@@ -563,7 +563,6 @@ class Contract extends Artifact {
563
563
  addressToCodeHash.set(result.address, result.codeHash);
564
564
  result.contracts.forEach((contract) => addressToCodeHash.set(contract.address, contract.codeHash));
565
565
  return {
566
- address: result.address,
567
566
  contractId: (0, utils_1.binToHex)((0, utils_1.contractIdFromAddress)(result.address)),
568
567
  contractAddress: result.address,
569
568
  returns: (0, api_1.fromApiArray)(result.returns, this.functions[`${methodIndex}`].returnTypes),
package/dist/src/index.js CHANGED
@@ -44,6 +44,9 @@ var __importStar = (this && this.__importStar) || function (mod) {
44
44
  };
45
45
  Object.defineProperty(exports, "__esModule", { value: true });
46
46
  exports.utils = exports.web3 = void 0;
47
+ BigInt.prototype['toJSON'] = function () {
48
+ return this.toString();
49
+ };
47
50
  __exportStar(require("./api"), exports);
48
51
  __exportStar(require("./contract"), exports);
49
52
  __exportStar(require("./signer"), exports);
@@ -1,4 +1,5 @@
1
1
  /** This source is under MIT License and come originally from https://github.com/cryptocoinjs/bs58 **/
2
2
  import basex from 'base-x';
3
3
  export declare const bs58: basex.BaseConverter;
4
+ export declare function isBase58(s: string): boolean;
4
5
  export default bs58;
@@ -20,9 +20,21 @@ 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.bs58 = void 0;
23
+ exports.isBase58 = exports.bs58 = void 0;
24
24
  /** This source is under MIT License and come originally from https://github.com/cryptocoinjs/bs58 **/
25
25
  const base_x_1 = __importDefault(require("base-x"));
26
26
  const ALPHABET = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz';
27
27
  exports.bs58 = (0, base_x_1.default)(ALPHABET);
28
+ function isBase58(s) {
29
+ if (s === '' || s.trim() === '') {
30
+ return false;
31
+ }
32
+ try {
33
+ return exports.bs58.encode(exports.bs58.decode(s)) === s;
34
+ }
35
+ catch (err) {
36
+ return false;
37
+ }
38
+ }
39
+ exports.isBase58 = isBase58;
28
40
  exports.default = exports.bs58;
@@ -8,6 +8,7 @@ export declare function contractIdFromAddress(address: string): Uint8Array;
8
8
  export declare function tokenIdFromAddress(address: string): Uint8Array;
9
9
  export declare function hexToBinUnsafe(hex: string): Uint8Array;
10
10
  export declare function binToHex(bin: Uint8Array): string;
11
+ export declare function groupOfPrivateKey(privateKey: string): number;
11
12
  export declare function publicKeyFromPrivateKey(privateKey: string): string;
12
13
  export declare function addressFromPublicKey(publicKey: string): string;
13
14
  export declare function addressFromContractId(contractId: string): string;
@@ -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.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.xorByte = exports.signatureDecode = exports.signatureEncode = void 0;
23
+ exports.assertType = exports.timeout = exports.hexToString = exports.stringToHex = exports.subContractId = exports.contractIdFromTx = exports.addressFromContractId = exports.addressFromPublicKey = exports.publicKeyFromPrivateKey = exports.groupOfPrivateKey = exports.binToHex = exports.hexToBinUnsafe = exports.tokenIdFromAddress = exports.contractIdFromAddress = exports.groupOfAddress = exports.isHexString = exports.xorByte = exports.signatureDecode = exports.signatureEncode = 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"));
@@ -147,6 +147,10 @@ function binToHex(bin) {
147
147
  return buffer_1.Buffer.from(bin).toString('hex');
148
148
  }
149
149
  exports.binToHex = binToHex;
150
+ function groupOfPrivateKey(privateKey) {
151
+ return groupOfAddress(addressFromPublicKey(publicKeyFromPrivateKey(privateKey)));
152
+ }
153
+ exports.groupOfPrivateKey = groupOfPrivateKey;
150
154
  function publicKeyFromPrivateKey(privateKey) {
151
155
  const key = ec.keyFromPrivate(privateKey);
152
156
  return key.getPublic(true, 'hex');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alephium/web3",
3
- "version": "0.2.0-rc.19",
3
+ "version": "0.2.0-rc.20",
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,7 +27,7 @@
27
27
  },
28
28
  "author": "Alephium dev <dev@alephium.org>",
29
29
  "config": {
30
- "alephium_version": "1.5.0-rc9",
30
+ "alephium_version": "1.5.0-rc10",
31
31
  "explorer_backend_version": "1.9.0-rc0"
32
32
  },
33
33
  "scripts": {
@@ -40,6 +40,7 @@ import { SignDeployContractTxParams, SignExecuteScriptTxParams, SignerWithNodePr
40
40
  import * as ralph from './ralph'
41
41
  import { bs58, binToHex, contractIdFromAddress, assertType, Eq } from '../utils'
42
42
  import { getCurrentNodeProvider } from '../global'
43
+ import { web3 } from '..'
43
44
 
44
45
  export type FieldsSig = node.FieldsSig
45
46
  export type EventSig = node.EventSig
@@ -196,7 +197,6 @@ export class Project {
196
197
 
197
198
  readonly contractsRootDir: string
198
199
  readonly artifactsRootDir: string
199
- readonly nodeProvider: NodeProvider
200
200
 
201
201
  static currentProject: Project
202
202
 
@@ -250,7 +250,6 @@ export class Project {
250
250
  }
251
251
 
252
252
  private constructor(
253
- provider: NodeProvider,
254
253
  contractsRootDir: string,
255
254
  artifactsRootDir: string,
256
255
  sourceFiles: SourceFile[],
@@ -259,7 +258,6 @@ export class Project {
259
258
  errorOnWarnings: boolean,
260
259
  projectArtifact: ProjectArtifact
261
260
  ) {
262
- this.nodeProvider = provider
263
261
  this.contractsRootDir = contractsRootDir
264
262
  this.artifactsRootDir = artifactsRootDir
265
263
  this.sourceFiles = sourceFiles
@@ -368,7 +366,6 @@ export class Project {
368
366
  })
369
367
  const projectArtifact = Project.buildProjectArtifact(files, contracts, scripts, compilerOptions)
370
368
  const project = new Project(
371
- provider,
372
369
  contractsRootDir,
373
370
  artifactsRootDir,
374
371
  files,
@@ -410,7 +407,6 @@ export class Project {
410
407
  }
411
408
 
412
409
  return new Project(
413
- provider,
414
410
  contractsRootDir,
415
411
  artifactsRootDir,
416
412
  files,
@@ -608,7 +604,7 @@ export class Contract extends Artifact {
608
604
  }
609
605
 
610
606
  async fetchState(address: string, group: number): Promise<ContractState> {
611
- const state = await Project.currentProject.nodeProvider.contracts.getContractsAddressState(address, {
607
+ const state = await web3.getCurrentNodeProvider().contracts.getContractsAddressState(address, {
612
608
  group: group
613
609
  })
614
610
  return this.fromApiContractState(state)
@@ -662,7 +658,7 @@ export class Contract extends Artifact {
662
658
  printDebugMessages: boolean
663
659
  ): Promise<TestContractResult> {
664
660
  const apiParams: node.TestContract = this.toTestContract(funcName, params)
665
- const apiResult = await Project.currentProject.nodeProvider.contracts.postContractsTestContract(apiParams)
661
+ const apiResult = await web3.getCurrentNodeProvider().contracts.postContractsTestContract(apiParams)
666
662
 
667
663
  const methodIndex =
668
664
  typeof params.testMethodIndex !== 'undefined' ? params.testMethodIndex : this.getMethodIndex(funcName)
@@ -791,7 +787,6 @@ export class Contract extends Artifact {
791
787
  addressToCodeHash.set(result.address, result.codeHash)
792
788
  result.contracts.forEach((contract) => addressToCodeHash.set(contract.address, contract.codeHash))
793
789
  return {
794
- address: result.address,
795
790
  contractId: binToHex(contractIdFromAddress(result.address)),
796
791
  contractAddress: result.address,
797
792
  returns: fromApiArray(result.returns, this.functions[`${methodIndex}`].returnTypes),
@@ -1047,7 +1042,6 @@ export interface ContractEventByTxId {
1047
1042
  export type DebugMessage = node.DebugMessage
1048
1043
 
1049
1044
  export interface TestContractResult {
1050
- address: string
1051
1045
  contractId: string
1052
1046
  contractAddress: string
1053
1047
  returns: Val[]
package/src/index.ts CHANGED
@@ -16,6 +16,10 @@ You should have received a copy of the GNU Lesser General Public License
16
16
  along with the library. If not, see <http://www.gnu.org/licenses/>.
17
17
  */
18
18
 
19
+ BigInt.prototype['toJSON'] = function () {
20
+ return this.toString()
21
+ }
22
+
19
23
  export * from './api'
20
24
  export * from './contract'
21
25
  export * from './signer'
package/src/utils/bs58.ts CHANGED
@@ -23,4 +23,15 @@ const ALPHABET = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'
23
23
 
24
24
  export const bs58 = basex(ALPHABET)
25
25
 
26
+ export function isBase58(s: string): boolean {
27
+ if (s === '' || s.trim() === '') {
28
+ return false
29
+ }
30
+ try {
31
+ return bs58.encode(bs58.decode(s)) === s
32
+ } catch (err) {
33
+ return false
34
+ }
35
+ }
36
+
26
37
  export default bs58
@@ -151,6 +151,10 @@ export function binToHex(bin: Uint8Array): string {
151
151
  return Buffer.from(bin).toString('hex')
152
152
  }
153
153
 
154
+ export function groupOfPrivateKey(privateKey: string): number {
155
+ return groupOfAddress(addressFromPublicKey(publicKeyFromPrivateKey(privateKey)))
156
+ }
157
+
154
158
  export function publicKeyFromPrivateKey(privateKey: string): string {
155
159
  const key = ec.keyFromPrivate(privateKey)
156
160
  return key.getPublic(true, 'hex')