@alephium/web3 0.23.0 → 0.24.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.
- package/dist/alephium-web3.min.js +1 -1
- package/dist/alephium-web3.min.js.map +1 -1
- package/dist/src/utils/exchange.d.ts +1 -1
- package/dist/src/utils/exchange.js +17 -6
- package/dist/src/utils/index.d.ts +1 -1
- package/dist/src/utils/index.js +2 -2
- package/package.json +1 -1
- package/src/utils/exchange.ts +14 -4
- package/src/utils/index.ts +6 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Transaction } from '../api/api-alephium';
|
|
2
2
|
import { Address } from '../signer';
|
|
3
|
-
export declare function
|
|
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.
|
|
20
|
+
exports.getAddressFromUnlockScript = exports.getDepositAddress = exports.isDepositTokenTransaction = exports.isDepositALPHTransaction = exports.validateExchangeAddress = void 0;
|
|
21
21
|
const __1 = require("..");
|
|
22
|
-
function
|
|
23
|
-
|
|
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
|
-
|
|
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.
|
|
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 {
|
|
9
|
+
export { validateExchangeAddress, isDepositALPHTransaction, isDepositTokenTransaction, getDepositAddress } from './exchange';
|
package/dist/src/utils/index.js
CHANGED
|
@@ -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.
|
|
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, "
|
|
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
package/src/utils/exchange.ts
CHANGED
|
@@ -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
|
|
24
|
-
|
|
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
|
-
|
|
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)
|
package/src/utils/index.ts
CHANGED
|
@@ -24,4 +24,9 @@ export * from './utils'
|
|
|
24
24
|
export * from './subscription'
|
|
25
25
|
export * from './sign'
|
|
26
26
|
export * from './number'
|
|
27
|
-
export {
|
|
27
|
+
export {
|
|
28
|
+
validateExchangeAddress,
|
|
29
|
+
isDepositALPHTransaction,
|
|
30
|
+
isDepositTokenTransaction,
|
|
31
|
+
getDepositAddress
|
|
32
|
+
} from './exchange'
|