@alephium/web3 0.2.2 → 0.3.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.
@@ -347,7 +347,7 @@ export interface CompilerOptions {
347
347
  ignoreUnusedFieldsWarnings?: boolean;
348
348
  ignoreUnusedPrivateFunctionsWarnings?: boolean;
349
349
  ignoreUpdateFieldsCheckWarnings?: boolean;
350
- ignoreExternalCallCheckWarnings?: boolean;
350
+ ignoreCheckExternalCallerWarnings?: boolean;
351
351
  }
352
352
  export interface Confirmed {
353
353
  /** @format block-hash */
@@ -737,11 +737,11 @@ export interface UTXO {
737
737
  ref: OutputRef;
738
738
  /** @format uint256 */
739
739
  amount: string;
740
- tokens: Token[];
740
+ tokens?: Token[];
741
741
  /** @format int64 */
742
- lockTime: number;
742
+ lockTime?: number;
743
743
  /** @format hex-string */
744
- additionalData: string;
744
+ additionalData?: string;
745
745
  }
746
746
  export interface UTXOs {
747
747
  utxos: UTXO[];
@@ -908,7 +908,7 @@ export declare class HttpClient<SecurityDataType = unknown> {
908
908
  }
909
909
  /**
910
910
  * @title Alephium API
911
- * @version 1.5.3
911
+ * @version 1.6.0
912
912
  * @baseUrl ../
913
913
  */
914
914
  export declare class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDataType> {
@@ -149,7 +149,7 @@ class HttpClient {
149
149
  exports.HttpClient = HttpClient;
150
150
  /**
151
151
  * @title Alephium API
152
- * @version 1.5.3
152
+ * @version 1.6.0
153
153
  * @baseUrl ../
154
154
  */
155
155
  class Api extends HttpClient {
@@ -91,6 +91,8 @@ export interface Input {
91
91
  outputRef: OutputRef;
92
92
  /** @format hex-string */
93
93
  unlockScript?: string;
94
+ /** @format 32-byte-hash */
95
+ txHashRef?: string;
94
96
  address?: string;
95
97
  /** @format uint256 */
96
98
  attoAlphAmount?: string;
@@ -352,6 +354,18 @@ export declare class Api<SecurityDataType extends unknown> extends HttpClient<Se
352
354
  limit?: number;
353
355
  reverse?: boolean;
354
356
  }, params?: RequestParams) => Promise<Transaction[]>;
357
+ /**
358
+ * @description List transactions for given addresses
359
+ *
360
+ * @tags Addresses
361
+ * @name PostAddressesTransactions
362
+ * @request POST:/addresses/transactions
363
+ */
364
+ postAddressesTransactions: (query?: {
365
+ page?: number;
366
+ limit?: number;
367
+ reverse?: boolean;
368
+ }, data?: string[], params?: RequestParams) => Promise<Transaction[]>;
355
369
  /**
356
370
  * @description List transactions of a given address within a time-range
357
371
  *
@@ -418,6 +432,17 @@ export declare class Api<SecurityDataType extends unknown> extends HttpClient<Se
418
432
  * @request GET:/addresses/{address}/tokens/{token_id}/balance
419
433
  */
420
434
  getAddressesAddressTokensTokenIdBalance: (address: string, tokenId: string, params?: RequestParams) => Promise<AddressBalance>;
435
+ /**
436
+ * No description
437
+ *
438
+ * @tags Addresses
439
+ * @name GetAddressesAddressExportTransactionsCsv
440
+ * @request GET:/addresses/{address}/export-transactions/csv
441
+ */
442
+ getAddressesAddressExportTransactionsCsv: (address: string, query: {
443
+ fromTs: number;
444
+ toTs: number;
445
+ }, params?: RequestParams) => Promise<string>;
421
446
  };
422
447
  addressesActive: {
423
448
  /**
@@ -253,6 +253,22 @@ class Api extends HttpClient {
253
253
  format: 'json',
254
254
  ...params
255
255
  }).then(utils_1.convertHttpResponse),
256
+ /**
257
+ * @description List transactions for given addresses
258
+ *
259
+ * @tags Addresses
260
+ * @name PostAddressesTransactions
261
+ * @request POST:/addresses/transactions
262
+ */
263
+ postAddressesTransactions: (query, data, params = {}) => this.request({
264
+ path: `/addresses/transactions`,
265
+ method: 'POST',
266
+ query: query,
267
+ body: data,
268
+ type: ContentType.Json,
269
+ format: 'json',
270
+ ...params
271
+ }).then(utils_1.convertHttpResponse),
256
272
  /**
257
273
  * @description List transactions of a given address within a time-range
258
274
  *
@@ -345,6 +361,19 @@ class Api extends HttpClient {
345
361
  method: 'GET',
346
362
  format: 'json',
347
363
  ...params
364
+ }).then(utils_1.convertHttpResponse),
365
+ /**
366
+ * No description
367
+ *
368
+ * @tags Addresses
369
+ * @name GetAddressesAddressExportTransactionsCsv
370
+ * @request GET:/addresses/{address}/export-transactions/csv
371
+ */
372
+ getAddressesAddressExportTransactionsCsv: (address, query, params = {}) => this.request({
373
+ path: `/addresses/${address}/export-transactions/csv`,
374
+ method: 'GET',
375
+ query: query,
376
+ ...params
348
377
  }).then(utils_1.convertHttpResponse)
349
378
  };
350
379
  this.addressesActive = {
@@ -1,2 +1,3 @@
1
1
  export declare const TOTAL_NUMBER_OF_GROUPS = 4;
2
2
  export declare const MIN_UTXO_SET_AMOUNT: bigint;
3
+ export declare const ALPH_TOKEN_ID: string;
@@ -17,6 +17,7 @@ You should have received a copy of the GNU Lesser General Public License
17
17
  along with the library. If not, see <http://www.gnu.org/licenses/>.
18
18
  */
19
19
  Object.defineProperty(exports, "__esModule", { value: true });
20
- exports.MIN_UTXO_SET_AMOUNT = exports.TOTAL_NUMBER_OF_GROUPS = void 0;
20
+ exports.ALPH_TOKEN_ID = exports.MIN_UTXO_SET_AMOUNT = exports.TOTAL_NUMBER_OF_GROUPS = void 0;
21
21
  exports.TOTAL_NUMBER_OF_GROUPS = 4;
22
22
  exports.MIN_UTXO_SET_AMOUNT = BigInt(1000000000000);
23
+ exports.ALPH_TOKEN_ID = ''.padStart(64, '0');
@@ -66,7 +66,7 @@ exports.DEFAULT_NODE_COMPILER_OPTIONS = {
66
66
  ignoreUnusedFieldsWarnings: false,
67
67
  ignoreUnusedPrivateFunctionsWarnings: false,
68
68
  ignoreUpdateFieldsCheckWarnings: false,
69
- ignoreExternalCallCheckWarnings: false
69
+ ignoreCheckExternalCallerWarnings: false
70
70
  };
71
71
  exports.DEFAULT_COMPILER_OPTIONS = { errorOnWarnings: true, ...exports.DEFAULT_NODE_COMPILER_OPTIONS };
72
72
  class TypedMatcher {
@@ -1,5 +1,10 @@
1
1
  import { ec as EC, SignatureInput } from 'elliptic';
2
- export declare function signatureEncode(signature: EC.Signature): string;
2
+ import BN from 'bn.js';
3
+ export declare function encodeSignature(signature: EC.Signature | {
4
+ r: BN;
5
+ s: BN;
6
+ }): string;
7
+ export declare function encodeHexSignature(rHex: string, sHex: string): string;
3
8
  export declare function signatureDecode(ec: EC, signature: string): SignatureInput;
4
9
  export declare function xorByte(intValue: number): number;
5
10
  export declare function isHexString(input: string): boolean;
@@ -13,7 +18,7 @@ export declare function publicKeyFromPrivateKey(privateKey: string): string;
13
18
  export declare function addressFromPublicKey(publicKey: string): string;
14
19
  export declare function addressFromContractId(contractId: string): string;
15
20
  export declare function contractIdFromTx(txId: string, outputIndex: number): string;
16
- export declare function subContractId(parentContractId: string, pathInHex: string): string;
21
+ export declare function subContractId(parentContractId: string, pathInHex: string, group: number): string;
17
22
  export declare function stringToHex(str: string): string;
18
23
  export declare function hexToString(str: string): string;
19
24
  export declare function timeout(ms: number): Promise<void>;
@@ -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.groupOfPrivateKey = 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.encodeHexSignature = exports.encodeSignature = 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"));
@@ -29,7 +29,7 @@ const buffer_1 = require("buffer/");
29
29
  const constants_1 = require("../constants");
30
30
  const djb2_1 = __importDefault(require("./djb2"));
31
31
  const ec = new elliptic_1.ec('secp256k1');
32
- function signatureEncode(signature) {
32
+ function encodeSignature(signature) {
33
33
  let sNormalized = signature.s;
34
34
  if (ec.n && signature.s.cmp(ec.nh) === 1) {
35
35
  sNormalized = ec.n.sub(signature.s);
@@ -38,7 +38,11 @@ function signatureEncode(signature) {
38
38
  const s = sNormalized.toString('hex', 66).slice(2);
39
39
  return r + s;
40
40
  }
41
- exports.signatureEncode = signatureEncode;
41
+ exports.encodeSignature = encodeSignature;
42
+ function encodeHexSignature(rHex, sHex) {
43
+ return encodeSignature({ r: new bn_js_1.default(rHex, 'hex'), s: new bn_js_1.default(sHex, 'hex') });
44
+ }
45
+ exports.encodeHexSignature = encodeHexSignature;
42
46
  // the signature should be in hex string format for 64 bytes
43
47
  function signatureDecode(ec, signature) {
44
48
  if (signature.length !== 128) {
@@ -64,7 +68,7 @@ function xorByte(intValue) {
64
68
  }
65
69
  exports.xorByte = xorByte;
66
70
  function isHexString(input) {
67
- return input.length % 2 === 0 && /[0-9a-f]*$/.test(input);
71
+ return input.length % 2 === 0 && /^[0-9a-fA-F]*$/.test(input);
68
72
  }
69
73
  exports.isHexString = isHexString;
70
74
  var AddressType;
@@ -177,9 +181,16 @@ function contractIdFromTx(txId, outputIndex) {
177
181
  return binToHex(hash);
178
182
  }
179
183
  exports.contractIdFromTx = contractIdFromTx;
180
- function subContractId(parentContractId, pathInHex) {
184
+ function subContractId(parentContractId, pathInHex, group) {
185
+ if (group < 0 || group >= constants_1.TOTAL_NUMBER_OF_GROUPS) {
186
+ throw new Error(`Invalid group ${group}`);
187
+ }
181
188
  const data = buffer_1.Buffer.concat([hexToBinUnsafe(parentContractId), hexToBinUnsafe(pathInHex)]);
182
- return binToHex(blakejs_1.default.blake2b(blakejs_1.default.blake2b(data, undefined, 32), undefined, 32));
189
+ const bytes = buffer_1.Buffer.concat([
190
+ blakejs_1.default.blake2b(blakejs_1.default.blake2b(data, undefined, 32), undefined, 32).slice(0, -1),
191
+ buffer_1.Buffer.from([group])
192
+ ]);
193
+ return binToHex(bytes);
183
194
  }
184
195
  exports.subContractId = subContractId;
185
196
  function stringToHex(str) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alephium/web3",
3
- "version": "0.2.2",
3
+ "version": "0.3.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,8 +27,8 @@
27
27
  },
28
28
  "author": "Alephium dev <dev@alephium.org>",
29
29
  "config": {
30
- "alephium_version": "1.5.3",
31
- "explorer_backend_version": "1.9.0"
30
+ "alephium_version": "1.6.0-rc5",
31
+ "explorer_backend_version": "1.11.2"
32
32
  },
33
33
  "scripts": {
34
34
  "build": "rm -rf dist/* && npx tsc --build . && webpack",
@@ -49,6 +49,7 @@
49
49
  },
50
50
  "devDependencies": {
51
51
  "@babel/eslint-parser": "^7.18.9",
52
+ "@types/elliptic": "^6.4.13",
52
53
  "@types/find-up": "^2.1.0",
53
54
  "@types/fs-extra": "^9.0.13",
54
55
  "@types/jest": "^27.5.1",
@@ -472,7 +472,7 @@ export interface CompilerOptions {
472
472
  ignoreUnusedFieldsWarnings?: boolean
473
473
  ignoreUnusedPrivateFunctionsWarnings?: boolean
474
474
  ignoreUpdateFieldsCheckWarnings?: boolean
475
- ignoreExternalCallCheckWarnings?: boolean
475
+ ignoreCheckExternalCallerWarnings?: boolean
476
476
  }
477
477
 
478
478
  export interface Confirmed {
@@ -979,13 +979,13 @@ export interface UTXO {
979
979
 
980
980
  /** @format uint256 */
981
981
  amount: string
982
- tokens: Token[]
982
+ tokens?: Token[]
983
983
 
984
984
  /** @format int64 */
985
- lockTime: number
985
+ lockTime?: number
986
986
 
987
987
  /** @format hex-string */
988
- additionalData: string
988
+ additionalData?: string
989
989
  }
990
990
 
991
991
  export interface UTXOs {
@@ -1332,7 +1332,7 @@ export class HttpClient<SecurityDataType = unknown> {
1332
1332
 
1333
1333
  /**
1334
1334
  * @title Alephium API
1335
- * @version 1.5.3
1335
+ * @version 1.6.0
1336
1336
  * @baseUrl ../
1337
1337
  */
1338
1338
  export class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDataType> {
@@ -133,6 +133,9 @@ export interface Input {
133
133
 
134
134
  /** @format hex-string */
135
135
  unlockScript?: string
136
+
137
+ /** @format 32-byte-hash */
138
+ txHashRef?: string
136
139
  address?: string
137
140
 
138
141
  /** @format uint256 */
@@ -637,6 +640,28 @@ export class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDa
637
640
  ...params
638
641
  }).then(convertHttpResponse),
639
642
 
643
+ /**
644
+ * @description List transactions for given addresses
645
+ *
646
+ * @tags Addresses
647
+ * @name PostAddressesTransactions
648
+ * @request POST:/addresses/transactions
649
+ */
650
+ postAddressesTransactions: (
651
+ query?: { page?: number; limit?: number; reverse?: boolean },
652
+ data?: string[],
653
+ params: RequestParams = {}
654
+ ) =>
655
+ this.request<Transaction[], BadRequest | Unauthorized | NotFound | InternalServerError | ServiceUnavailable>({
656
+ path: `/addresses/transactions`,
657
+ method: 'POST',
658
+ query: query,
659
+ body: data,
660
+ type: ContentType.Json,
661
+ format: 'json',
662
+ ...params
663
+ }).then(convertHttpResponse),
664
+
640
665
  /**
641
666
  * @description List transactions of a given address within a time-range
642
667
  *
@@ -751,6 +776,25 @@ export class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDa
751
776
  method: 'GET',
752
777
  format: 'json',
753
778
  ...params
779
+ }).then(convertHttpResponse),
780
+
781
+ /**
782
+ * No description
783
+ *
784
+ * @tags Addresses
785
+ * @name GetAddressesAddressExportTransactionsCsv
786
+ * @request GET:/addresses/{address}/export-transactions/csv
787
+ */
788
+ getAddressesAddressExportTransactionsCsv: (
789
+ address: string,
790
+ query: { fromTs: number; toTs: number },
791
+ params: RequestParams = {}
792
+ ) =>
793
+ this.request<string, BadRequest | Unauthorized | NotFound | InternalServerError | ServiceUnavailable>({
794
+ path: `/addresses/${address}/export-transactions/csv`,
795
+ method: 'GET',
796
+ query: query,
797
+ ...params
754
798
  }).then(convertHttpResponse)
755
799
  }
756
800
  addressesActive = {
package/src/constants.ts CHANGED
@@ -18,3 +18,4 @@ along with the library. If not, see <http://www.gnu.org/licenses/>.
18
18
 
19
19
  export const TOTAL_NUMBER_OF_GROUPS = 4
20
20
  export const MIN_UTXO_SET_AMOUNT = BigInt(1000000000000)
21
+ export const ALPH_TOKEN_ID = ''.padStart(64, '0')
@@ -70,7 +70,7 @@ export const DEFAULT_NODE_COMPILER_OPTIONS: node.CompilerOptions = {
70
70
  ignoreUnusedFieldsWarnings: false,
71
71
  ignoreUnusedPrivateFunctionsWarnings: false,
72
72
  ignoreUpdateFieldsCheckWarnings: false,
73
- ignoreExternalCallCheckWarnings: false
73
+ ignoreCheckExternalCallerWarnings: false
74
74
  }
75
75
 
76
76
  export const DEFAULT_COMPILER_OPTIONS: CompilerOptions = { errorOnWarnings: true, ...DEFAULT_NODE_COMPILER_OPTIONS }
@@ -27,7 +27,7 @@ import djb2 from './djb2'
27
27
 
28
28
  const ec = new EC('secp256k1')
29
29
 
30
- export function signatureEncode(signature: EC.Signature): string {
30
+ export function encodeSignature(signature: EC.Signature | { r: BN; s: BN }): string {
31
31
  let sNormalized = signature.s
32
32
  if (ec.n && signature.s.cmp(ec.nh) === 1) {
33
33
  sNormalized = ec.n.sub(signature.s)
@@ -38,6 +38,10 @@ export function signatureEncode(signature: EC.Signature): string {
38
38
  return r + s
39
39
  }
40
40
 
41
+ export function encodeHexSignature(rHex: string, sHex: string): string {
42
+ return encodeSignature({ r: new BN(rHex, 'hex'), s: new BN(sHex, 'hex') })
43
+ }
44
+
41
45
  // the signature should be in hex string format for 64 bytes
42
46
  export function signatureDecode(ec: EC, signature: string): SignatureInput {
43
47
  if (signature.length !== 128) {
@@ -63,7 +67,7 @@ export function xorByte(intValue: number): number {
63
67
  }
64
68
 
65
69
  export function isHexString(input: string): boolean {
66
- return input.length % 2 === 0 && /[0-9a-f]*$/.test(input)
70
+ return input.length % 2 === 0 && /^[0-9a-fA-F]*$/.test(input)
67
71
  }
68
72
 
69
73
  enum AddressType {
@@ -181,10 +185,16 @@ export function contractIdFromTx(txId: string, outputIndex: number): string {
181
185
  return binToHex(hash)
182
186
  }
183
187
 
184
- export function subContractId(parentContractId: string, pathInHex: string): string {
188
+ export function subContractId(parentContractId: string, pathInHex: string, group: number): string {
189
+ if (group < 0 || group >= TOTAL_NUMBER_OF_GROUPS) {
190
+ throw new Error(`Invalid group ${group}`)
191
+ }
185
192
  const data = Buffer.concat([hexToBinUnsafe(parentContractId), hexToBinUnsafe(pathInHex)])
186
-
187
- return binToHex(blake.blake2b(blake.blake2b(data, undefined, 32), undefined, 32))
193
+ const bytes = Buffer.concat([
194
+ blake.blake2b(blake.blake2b(data, undefined, 32), undefined, 32).slice(0, -1),
195
+ Buffer.from([group])
196
+ ])
197
+ return binToHex(bytes)
188
198
  }
189
199
 
190
200
  export function stringToHex(str: string): string {