@alephium/web3 0.23.0 → 0.25.0

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.
@@ -5,3 +5,7 @@ export declare const ALPH_TOKEN_ID: string;
5
5
  export declare const ONE_ALPH: bigint;
6
6
  export declare const DUST_AMOUNT: bigint;
7
7
  export declare const ZERO_ADDRESS = "tgx7VNFoP9DJiFMFgXXtafQZkUvyEdDHT9ryamHJYrjq";
8
+ export declare const DEFAULT_GAS_AMOUNT = 20000;
9
+ export declare const DEFAULT_GAS_PRICE: bigint;
10
+ export declare const DEFAULT_GAS_ATTOALPH_AMOUNT: bigint;
11
+ export declare const DEFAULT_GAS_ALPH_AMOUNT = 0.002;
@@ -17,7 +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.ZERO_ADDRESS = exports.DUST_AMOUNT = exports.ONE_ALPH = exports.ALPH_TOKEN_ID = exports.MIN_UTXO_SET_AMOUNT = exports.TOTAL_NUMBER_OF_CHAINS = exports.TOTAL_NUMBER_OF_GROUPS = void 0;
20
+ exports.DEFAULT_GAS_ALPH_AMOUNT = exports.DEFAULT_GAS_ATTOALPH_AMOUNT = exports.DEFAULT_GAS_PRICE = exports.DEFAULT_GAS_AMOUNT = exports.ZERO_ADDRESS = exports.DUST_AMOUNT = exports.ONE_ALPH = exports.ALPH_TOKEN_ID = exports.MIN_UTXO_SET_AMOUNT = exports.TOTAL_NUMBER_OF_CHAINS = exports.TOTAL_NUMBER_OF_GROUPS = void 0;
21
21
  exports.TOTAL_NUMBER_OF_GROUPS = 4;
22
22
  exports.TOTAL_NUMBER_OF_CHAINS = exports.TOTAL_NUMBER_OF_GROUPS * exports.TOTAL_NUMBER_OF_GROUPS;
23
23
  exports.MIN_UTXO_SET_AMOUNT = BigInt(1000000000000);
@@ -25,3 +25,7 @@ exports.ALPH_TOKEN_ID = ''.padStart(64, '0');
25
25
  exports.ONE_ALPH = 10n ** 18n;
26
26
  exports.DUST_AMOUNT = 10n ** 15n;
27
27
  exports.ZERO_ADDRESS = 'tgx7VNFoP9DJiFMFgXXtafQZkUvyEdDHT9ryamHJYrjq';
28
+ exports.DEFAULT_GAS_AMOUNT = 20000;
29
+ exports.DEFAULT_GAS_PRICE = 10n ** 11n;
30
+ exports.DEFAULT_GAS_ATTOALPH_AMOUNT = BigInt(exports.DEFAULT_GAS_AMOUNT) * exports.DEFAULT_GAS_PRICE;
31
+ exports.DEFAULT_GAS_ALPH_AMOUNT = 0.002;
@@ -1,6 +1,6 @@
1
1
  import { Transaction } from '../api/api-alephium';
2
2
  import { Address } from '../signer';
3
- export declare function isExchangeAddress(address: string): boolean;
3
+ export declare function validateExchangeAddress(address: string): void;
4
4
  export declare function isDepositALPHTransaction(tx: Transaction, exchangeAddress: string): boolean;
5
5
  export declare function isDepositTokenTransaction(tx: Transaction, exchangeAddress: string): boolean;
6
6
  export declare function getDepositAddress(tx: Transaction): Address;
@@ -17,16 +17,27 @@ 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.getAddressFromUnlockScript = exports.getDepositAddress = exports.isDepositTokenTransaction = exports.isDepositALPHTransaction = exports.isExchangeAddress = void 0;
20
+ exports.getAddressFromUnlockScript = exports.getDepositAddress = exports.isDepositTokenTransaction = exports.isDepositALPHTransaction = exports.validateExchangeAddress = void 0;
21
21
  const __1 = require("..");
22
- function isExchangeAddress(address) {
23
- const decoded = __1.bs58.decode(address);
22
+ function validateExchangeAddress(address) {
23
+ let decoded;
24
+ try {
25
+ decoded = __1.bs58.decode(address);
26
+ }
27
+ catch (_) {
28
+ throw new Error('Invalid base58 string');
29
+ }
24
30
  if (decoded.length === 0)
25
31
  throw new Error('Address is empty');
26
32
  const addressType = decoded[0];
27
- return (addressType === __1.AddressType.P2PKH || addressType === __1.AddressType.P2SH) && decoded.length === 33;
33
+ if (addressType !== __1.AddressType.P2PKH && addressType !== __1.AddressType.P2SH) {
34
+ throw new Error('Invalid address type');
35
+ }
36
+ if (decoded.length !== 33) {
37
+ throw new Error('Invalid address length');
38
+ }
28
39
  }
29
- exports.isExchangeAddress = isExchangeAddress;
40
+ exports.validateExchangeAddress = validateExchangeAddress;
30
41
  function isDepositALPHTransaction(tx, exchangeAddress) {
31
42
  return isDepositTransaction(tx, exchangeAddress) && checkALPHOutput(tx);
32
43
  }
@@ -112,7 +123,7 @@ function isDepositTransaction(tx, exchangeAddress) {
112
123
  return false;
113
124
  }
114
125
  const from = getFromAddress(tx);
115
- if (from === undefined) {
126
+ if (from === undefined || from === exchangeAddress) {
116
127
  return false;
117
128
  }
118
129
  return checkOutputAddress(tx, from, exchangeAddress);
@@ -6,4 +6,4 @@ export * from './utils';
6
6
  export * from './subscription';
7
7
  export * from './sign';
8
8
  export * from './number';
9
- export { isExchangeAddress, isDepositALPHTransaction, isDepositTokenTransaction, getDepositAddress } from './exchange';
9
+ export { validateExchangeAddress, isDepositALPHTransaction, isDepositTokenTransaction, getDepositAddress } from './exchange';
@@ -31,7 +31,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
31
31
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
32
32
  };
33
33
  Object.defineProperty(exports, "__esModule", { value: true });
34
- exports.getDepositAddress = exports.isDepositTokenTransaction = exports.isDepositALPHTransaction = exports.isExchangeAddress = void 0;
34
+ exports.getDepositAddress = exports.isDepositTokenTransaction = exports.isDepositALPHTransaction = exports.validateExchangeAddress = void 0;
35
35
  __exportStar(require("./webcrypto"), exports);
36
36
  __exportStar(require("./address"), exports);
37
37
  __exportStar(require("./bs58"), exports);
@@ -41,7 +41,7 @@ __exportStar(require("./subscription"), exports);
41
41
  __exportStar(require("./sign"), exports);
42
42
  __exportStar(require("./number"), exports);
43
43
  var exchange_1 = require("./exchange");
44
- Object.defineProperty(exports, "isExchangeAddress", { enumerable: true, get: function () { return exchange_1.isExchangeAddress; } });
44
+ Object.defineProperty(exports, "validateExchangeAddress", { enumerable: true, get: function () { return exchange_1.validateExchangeAddress; } });
45
45
  Object.defineProperty(exports, "isDepositALPHTransaction", { enumerable: true, get: function () { return exchange_1.isDepositALPHTransaction; } });
46
46
  Object.defineProperty(exports, "isDepositTokenTransaction", { enumerable: true, get: function () { return exchange_1.isDepositTokenTransaction; } });
47
47
  Object.defineProperty(exports, "getDepositAddress", { enumerable: true, get: function () { return exchange_1.getDepositAddress; } });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alephium/web3",
3
- "version": "0.23.0",
3
+ "version": "0.25.0",
4
4
  "description": "A JS/TS library to interact with the Alephium platform",
5
5
  "license": "GPL",
6
6
  "main": "dist/src/index.js",
package/src/constants.ts CHANGED
@@ -23,3 +23,7 @@ export const ALPH_TOKEN_ID = ''.padStart(64, '0')
23
23
  export const ONE_ALPH = 10n ** 18n
24
24
  export const DUST_AMOUNT = 10n ** 15n
25
25
  export const ZERO_ADDRESS = 'tgx7VNFoP9DJiFMFgXXtafQZkUvyEdDHT9ryamHJYrjq'
26
+ export const DEFAULT_GAS_AMOUNT = 20000
27
+ export const DEFAULT_GAS_PRICE = 10n ** 11n
28
+ export const DEFAULT_GAS_ATTOALPH_AMOUNT = BigInt(DEFAULT_GAS_AMOUNT) * DEFAULT_GAS_PRICE
29
+ export const DEFAULT_GAS_ALPH_AMOUNT = 0.002
@@ -20,11 +20,21 @@ import { AddressType, DUST_AMOUNT, addressFromPublicKey, addressFromScript, binT
20
20
  import { Transaction } from '../api/api-alephium'
21
21
  import { Address } from '../signer'
22
22
 
23
- export function isExchangeAddress(address: string): boolean {
24
- const decoded = bs58.decode(address)
23
+ export function validateExchangeAddress(address: string) {
24
+ let decoded: Uint8Array
25
+ try {
26
+ decoded = bs58.decode(address)
27
+ } catch (_) {
28
+ throw new Error('Invalid base58 string')
29
+ }
25
30
  if (decoded.length === 0) throw new Error('Address is empty')
26
31
  const addressType = decoded[0]
27
- return (addressType === AddressType.P2PKH || addressType === AddressType.P2SH) && decoded.length === 33
32
+ if (addressType !== AddressType.P2PKH && addressType !== AddressType.P2SH) {
33
+ throw new Error('Invalid address type')
34
+ }
35
+ if (decoded.length !== 33) {
36
+ throw new Error('Invalid address length')
37
+ }
28
38
  }
29
39
 
30
40
  export function isDepositALPHTransaction(tx: Transaction, exchangeAddress: string): boolean {
@@ -113,7 +123,7 @@ function isDepositTransaction(tx: Transaction, exchangeAddress: string): boolean
113
123
  return false
114
124
  }
115
125
  const from = getFromAddress(tx)
116
- if (from === undefined) {
126
+ if (from === undefined || from === exchangeAddress) {
117
127
  return false
118
128
  }
119
129
  return checkOutputAddress(tx, from, exchangeAddress)
@@ -24,4 +24,9 @@ export * from './utils'
24
24
  export * from './subscription'
25
25
  export * from './sign'
26
26
  export * from './number'
27
- export { isExchangeAddress, isDepositALPHTransaction, isDepositTokenTransaction, getDepositAddress } from './exchange'
27
+ export {
28
+ validateExchangeAddress,
29
+ isDepositALPHTransaction,
30
+ isDepositTokenTransaction,
31
+ getDepositAddress
32
+ } from './exchange'