@alephium/web3 2.0.8 → 2.0.11

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.
@@ -646,6 +646,8 @@ export interface ContractEvent {
646
646
  blockHash: string;
647
647
  /** @format 32-byte-hash */
648
648
  txId: string;
649
+ /** @format int64 */
650
+ timestamp: number;
649
651
  /** @format int32 */
650
652
  eventIndex: number;
651
653
  fields: Val[];
@@ -654,6 +656,8 @@ export interface ContractEvent {
654
656
  export interface ContractEventByBlockHash {
655
657
  /** @format 32-byte-hash */
656
658
  txId: string;
659
+ /** @format int64 */
660
+ timestamp: number;
657
661
  /** @format address */
658
662
  contractAddress: string;
659
663
  /** @format int32 */
@@ -664,6 +668,8 @@ export interface ContractEventByBlockHash {
664
668
  export interface ContractEventByTxId {
665
669
  /** @format block-hash */
666
670
  blockHash: string;
671
+ /** @format int64 */
672
+ timestamp: number;
667
673
  /** @format address */
668
674
  contractAddress: string;
669
675
  /** @format int32 */
@@ -1331,7 +1337,7 @@ export interface ValByteVec {
1331
1337
  }
1332
1338
  /** ValI256 */
1333
1339
  export interface ValI256 {
1334
- /** @format bigint */
1340
+ /** @format int256 */
1335
1341
  value: string;
1336
1342
  type: string;
1337
1343
  }
@@ -1446,7 +1452,7 @@ export declare class HttpClient<SecurityDataType = unknown> {
1446
1452
  }
1447
1453
  /**
1448
1454
  * @title Alephium API
1449
- * @version 4.2.5
1455
+ * @version 4.4.1
1450
1456
  * @baseUrl ../
1451
1457
  */
1452
1458
  export declare class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDataType> {
@@ -151,7 +151,7 @@ class HttpClient {
151
151
  exports.HttpClient = HttpClient;
152
152
  /**
153
153
  * @title Alephium API
154
- * @version 4.2.5
154
+ * @version 4.4.1
155
155
  * @baseUrl ../
156
156
  */
157
157
  class Api extends HttpClient {
@@ -148,6 +148,7 @@ export interface TestContractParams<F extends Fields = Fields, A extends Argumen
148
148
  export interface ContractEvent<T extends Fields = Fields> {
149
149
  txId: string;
150
150
  blockHash: string;
151
+ timestamp: number;
151
152
  contractAddress: string;
152
153
  eventIndex: number;
153
154
  name: string;
@@ -359,6 +359,7 @@ class Contract extends Artifact {
359
359
  return {
360
360
  txId: txId,
361
361
  blockHash: event.blockHash,
362
+ timestamp: event.timestamp,
362
363
  contractAddress: event.contractAddress,
363
364
  name: name,
364
365
  eventIndex: event.eventIndex,
@@ -792,6 +793,7 @@ function decodeContractCreatedEvent(event) {
792
793
  return {
793
794
  blockHash: event.blockHash,
794
795
  txId: event.txId,
796
+ timestamp: event.timestamp,
795
797
  eventIndex: event.eventIndex,
796
798
  name: Contract.ContractCreatedEvent.name,
797
799
  fields: toContractCreatedEventFields(fields)
@@ -803,6 +805,7 @@ function decodeContractDestroyedEvent(event) {
803
805
  return {
804
806
  blockHash: event.blockHash,
805
807
  txId: event.txId,
808
+ timestamp: event.timestamp,
806
809
  eventIndex: event.eventIndex,
807
810
  name: Contract.ContractDestroyedEvent.name,
808
811
  fields: { address: fields['address'] }
@@ -1252,13 +1255,39 @@ exports.subscribeContractEvents = subscribeContractEvents;
1252
1255
  async function callMethod(contract, instance, methodName, params, getContractByCodeHash) {
1253
1256
  const methodIndex = contract.contract.getMethodIndex(methodName);
1254
1257
  const txId = params?.txId ?? randomTxId();
1255
- const callParams = contract.contract.toApiCallContract({ ...params, txId: txId, args: params.args === undefined ? {} : params.args }, instance.groupIndex, instance.address, methodIndex);
1258
+ const callArgs = getCallMethodArgs(params.args ?? {}, instance.groupIndex);
1259
+ const callParams = contract.contract.toApiCallContract({ ...params, txId: txId, args: callArgs }, instance.groupIndex, instance.address, methodIndex);
1256
1260
  const result = await (0, global_1.getCurrentNodeProvider)().contracts.postContractsCallContract(callParams);
1257
1261
  const callResult = contract.contract.fromApiCallContractResult(result, txId, methodIndex, getContractByCodeHash);
1258
1262
  contract.contract.printDebugMessages(methodName, callResult.debugMessages);
1259
1263
  return callResult;
1260
1264
  }
1261
1265
  exports.callMethod = callMethod;
1266
+ function tryGetCallMethodAddressArg(maybeAddress, groupIndex) {
1267
+ if (!(0, address_1.isValidAddress)(maybeAddress))
1268
+ return maybeAddress;
1269
+ if ((0, address_1.isGrouplessAddress)(maybeAddress)) {
1270
+ const rawAddress = (0, address_1.addressWithoutExplicitGroupIndex)(maybeAddress);
1271
+ return `${rawAddress}:${groupIndex}`;
1272
+ }
1273
+ return maybeAddress;
1274
+ }
1275
+ function getCallMethodArgsFromVal(val, groupIndex) {
1276
+ if (typeof val === 'string') {
1277
+ return tryGetCallMethodAddressArg(val, groupIndex);
1278
+ }
1279
+ if (Array.isArray(val)) {
1280
+ return val.map((v) => getCallMethodArgsFromVal(v, groupIndex));
1281
+ }
1282
+ return val;
1283
+ }
1284
+ function getCallMethodArgs(args, groupIndex) {
1285
+ const newArgs = {};
1286
+ for (const [key, value] of Object.entries(args)) {
1287
+ newArgs[`${key}`] = getCallMethodArgsFromVal(value, groupIndex);
1288
+ }
1289
+ return newArgs;
1290
+ }
1262
1291
  async function signExecuteMethod(contract, instance, methodName, params) {
1263
1292
  const methodIndex = contract.contract.getMethodIndex(methodName);
1264
1293
  const functionSig = contract.contract.functions[methodIndex];
@@ -1451,7 +1480,8 @@ async function multicallMethods(contract, instance, _callss, getContractByCodeHa
1451
1480
  const [methodName, params] = entry;
1452
1481
  const methodIndex = contract.contract.getMethodIndex(methodName);
1453
1482
  const txId = params?.txId ?? randomTxId();
1454
- return contract.contract.toApiCallContract({ ...params, txId: txId, args: params.args === undefined ? {} : params.args }, instance.groupIndex, instance.address, methodIndex);
1483
+ const callArgs = getCallMethodArgs(params.args ?? {}, instance.groupIndex);
1484
+ return contract.contract.toApiCallContract({ ...params, txId: txId, args: callArgs }, instance.groupIndex, instance.address, methodIndex);
1455
1485
  });
1456
1486
  });
1457
1487
  const result = await (0, global_1.getCurrentNodeProvider)().contracts.postContractsMulticallContract({ calls: callsParams.flat() });
@@ -29,7 +29,8 @@ class WebCrypto {
29
29
  throw new TypeError("Failed to execute 'getRandomValues' on 'Crypto': parameter 1 is not of type 'ArrayBufferView'");
30
30
  }
31
31
  const bytes = new Uint8Array(array.buffer, array.byteOffset, array.byteLength);
32
- if (isBrowser) {
32
+ // Prefer global Web Crypto (e.g. react-native-get-random-values) for mobile compatibility
33
+ if (globalThis.crypto && typeof globalThis.crypto.getRandomValues === 'function') {
33
34
  globalThis.crypto.getRandomValues(bytes);
34
35
  }
35
36
  else {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alephium/web3",
3
- "version": "2.0.8",
3
+ "version": "2.0.11",
4
4
  "description": "A JS/TS library to interact with the Alephium platform",
5
5
  "license": "GPL",
6
6
  "main": "dist/src/index.js",
@@ -25,7 +25,7 @@
25
25
  },
26
26
  "repository": {
27
27
  "type": "git",
28
- "url": "git@github.com:alephium/alephium-web3.git"
28
+ "url": "git+https://github.com/alephium/alephium-web3.git"
29
29
  },
30
30
  "homepage": "https://github.com/alephium/alephium-web3",
31
31
  "bugs": {
@@ -33,7 +33,7 @@
33
33
  },
34
34
  "author": "Alephium dev <dev@alephium.org>",
35
35
  "config": {
36
- "alephium_version": "4.2.5",
36
+ "alephium_version": "4.4.1",
37
37
  "explorer_backend_version": "3.3.2"
38
38
  },
39
39
  "type": "commonjs",
@@ -723,6 +723,8 @@ export interface ContractEvent {
723
723
  blockHash: string
724
724
  /** @format 32-byte-hash */
725
725
  txId: string
726
+ /** @format int64 */
727
+ timestamp: number
726
728
  /** @format int32 */
727
729
  eventIndex: number
728
730
  fields: Val[]
@@ -732,6 +734,8 @@ export interface ContractEvent {
732
734
  export interface ContractEventByBlockHash {
733
735
  /** @format 32-byte-hash */
734
736
  txId: string
737
+ /** @format int64 */
738
+ timestamp: number
735
739
  /** @format address */
736
740
  contractAddress: string
737
741
  /** @format int32 */
@@ -743,6 +747,8 @@ export interface ContractEventByBlockHash {
743
747
  export interface ContractEventByTxId {
744
748
  /** @format block-hash */
745
749
  blockHash: string
750
+ /** @format int64 */
751
+ timestamp: number
746
752
  /** @format address */
747
753
  contractAddress: string
748
754
  /** @format int32 */
@@ -1503,7 +1509,7 @@ export interface ValByteVec {
1503
1509
 
1504
1510
  /** ValI256 */
1505
1511
  export interface ValI256 {
1506
- /** @format bigint */
1512
+ /** @format int256 */
1507
1513
  value: string
1508
1514
  type: string
1509
1515
  }
@@ -1780,7 +1786,7 @@ export class HttpClient<SecurityDataType = unknown> {
1780
1786
 
1781
1787
  /**
1782
1788
  * @title Alephium API
1783
- * @version 4.2.5
1789
+ * @version 4.4.1
1784
1790
  * @baseUrl ../
1785
1791
  */
1786
1792
  export class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDataType> {
@@ -59,7 +59,15 @@ import {
59
59
  isHexString,
60
60
  hexToString
61
61
  } from '../utils'
62
- import { contractIdFromAddress, groupOfAddress, addressFromContractId, subContractId } from '../address'
62
+ import {
63
+ contractIdFromAddress,
64
+ groupOfAddress,
65
+ addressFromContractId,
66
+ subContractId,
67
+ isGrouplessAddress,
68
+ isValidAddress,
69
+ addressWithoutExplicitGroupIndex
70
+ } from '../address'
63
71
  import { getCurrentNodeProvider } from '../global'
64
72
  import { EventSubscribeOptions, EventSubscription, subscribeToEvents } from './events'
65
73
  import { MINIMAL_CONTRACT_DEPOSIT, ONE_ALPH, TOTAL_NUMBER_OF_GROUPS } from '../constants'
@@ -559,6 +567,7 @@ export class Contract extends Artifact {
559
567
  return {
560
568
  txId: txId,
561
569
  blockHash: event.blockHash,
570
+ timestamp: event.timestamp,
562
571
  contractAddress: event.contractAddress,
563
572
  name: name,
564
573
  eventIndex: event.eventIndex,
@@ -1001,6 +1010,7 @@ export interface TestContractParams<
1001
1010
  export interface ContractEvent<T extends Fields = Fields> {
1002
1011
  txId: string
1003
1012
  blockHash: string
1013
+ timestamp: number
1004
1014
  contractAddress: string
1005
1015
  eventIndex: number
1006
1016
  name: string
@@ -1294,6 +1304,7 @@ export function decodeContractCreatedEvent(event: node.ContractEvent): Omit<Cont
1294
1304
  return {
1295
1305
  blockHash: event.blockHash,
1296
1306
  txId: event.txId,
1307
+ timestamp: event.timestamp,
1297
1308
  eventIndex: event.eventIndex,
1298
1309
  name: Contract.ContractCreatedEvent.name,
1299
1310
  fields: toContractCreatedEventFields(fields)
@@ -1307,6 +1318,7 @@ export function decodeContractDestroyedEvent(
1307
1318
  return {
1308
1319
  blockHash: event.blockHash,
1309
1320
  txId: event.txId,
1321
+ timestamp: event.timestamp,
1310
1322
  eventIndex: event.eventIndex,
1311
1323
  name: Contract.ContractDestroyedEvent.name,
1312
1324
  fields: { address: fields['address'] as Address }
@@ -1923,8 +1935,9 @@ export async function callMethod<I extends ContractInstance, F extends Fields, A
1923
1935
  ): Promise<CallContractResult<R>> {
1924
1936
  const methodIndex = contract.contract.getMethodIndex(methodName)
1925
1937
  const txId = params?.txId ?? randomTxId()
1938
+ const callArgs = getCallMethodArgs(params.args ?? {}, instance.groupIndex)
1926
1939
  const callParams = contract.contract.toApiCallContract(
1927
- { ...params, txId: txId, args: params.args === undefined ? {} : params.args },
1940
+ { ...params, txId: txId, args: callArgs },
1928
1941
  instance.groupIndex,
1929
1942
  instance.address,
1930
1943
  methodIndex
@@ -1935,6 +1948,33 @@ export async function callMethod<I extends ContractInstance, F extends Fields, A
1935
1948
  return callResult as CallContractResult<R>
1936
1949
  }
1937
1950
 
1951
+ function tryGetCallMethodAddressArg(maybeAddress: string, groupIndex: number): Val {
1952
+ if (!isValidAddress(maybeAddress)) return maybeAddress
1953
+ if (isGrouplessAddress(maybeAddress)) {
1954
+ const rawAddress = addressWithoutExplicitGroupIndex(maybeAddress)
1955
+ return `${rawAddress}:${groupIndex}`
1956
+ }
1957
+ return maybeAddress
1958
+ }
1959
+
1960
+ function getCallMethodArgsFromVal(val: Val, groupIndex: number): Val {
1961
+ if (typeof val === 'string') {
1962
+ return tryGetCallMethodAddressArg(val, groupIndex)
1963
+ }
1964
+ if (Array.isArray(val)) {
1965
+ return val.map((v) => getCallMethodArgsFromVal(v, groupIndex))
1966
+ }
1967
+ return val
1968
+ }
1969
+
1970
+ function getCallMethodArgs<A extends Arguments>(args: A, groupIndex: number): A {
1971
+ const newArgs: Arguments = {}
1972
+ for (const [key, value] of Object.entries(args)) {
1973
+ newArgs[`${key}`] = getCallMethodArgsFromVal(value, groupIndex)
1974
+ }
1975
+ return newArgs as A
1976
+ }
1977
+
1938
1978
  export async function signExecuteMethod<I extends ContractInstance, F extends Fields, A extends Arguments, R>(
1939
1979
  contract: ContractFactory<I, F>,
1940
1980
  instance: ContractInstance,
@@ -2199,8 +2239,9 @@ export async function multicallMethods<I extends ContractInstance, F extends Fie
2199
2239
  const [methodName, params] = entry
2200
2240
  const methodIndex = contract.contract.getMethodIndex(methodName)
2201
2241
  const txId = params?.txId ?? randomTxId()
2242
+ const callArgs = getCallMethodArgs(params.args ?? {}, instance.groupIndex)
2202
2243
  return contract.contract.toApiCallContract(
2203
- { ...params, txId: txId, args: params.args === undefined ? {} : params.args },
2244
+ { ...params, txId: txId, args: callArgs },
2204
2245
  instance.groupIndex,
2205
2246
  instance.address,
2206
2247
  methodIndex
@@ -31,7 +31,8 @@ export class WebCrypto {
31
31
  }
32
32
  const bytes = new Uint8Array(array.buffer, array.byteOffset, array.byteLength)
33
33
 
34
- if (isBrowser) {
34
+ // Prefer global Web Crypto (e.g. react-native-get-random-values) for mobile compatibility
35
+ if (globalThis.crypto && typeof globalThis.crypto.getRandomValues === 'function') {
35
36
  globalThis.crypto.getRandomValues(bytes)
36
37
  } else {
37
38
  randomFillSync(bytes)