UNPKG

@hdwallet/core

Version:

A complete Hierarchical Deterministic (HD) Wallet generator for 200+ cryptocurrencies, built with TypeScript.

37 lines 1.5 kB
// SPDX-License-Identifier: MIT import { Aptos } from '../cryptocurrencies'; import { sha3_256 } from '../crypto'; import { SLIP10Ed25519PublicKey, validateAndGetPublicKey } from '../eccs'; import { bytesToString, integerToBytes } from '../utils'; import { AddressError } from '../exceptions'; import { Address } from './address'; export class AptosAddress extends Address { static suffix = integerToBytes(Aptos.PARAMS.SUFFIX); static addressPrefix = Aptos.PARAMS.ADDRESS_PREFIX; static getName() { return 'Aptos'; } static encode(publicKey) { const pk = validateAndGetPublicKey(publicKey, SLIP10Ed25519PublicKey); const raw = pk.getRawCompressed().subarray(1); const payload = new Uint8Array([...raw, ...this.suffix]); const hash = sha3_256(payload); return this.addressPrefix + bytesToString(hash).replace(/^0+/, ''); } static decode(address) { const prefix = address.slice(0, this.addressPrefix.length); if (prefix !== this.addressPrefix) { throw new AddressError('Invalid address prefix', { expected: this.addressPrefix, got: prefix }); } const body = address.slice(this.addressPrefix.length).padStart(64, '0'); if (body.length !== 64) { throw new AddressError('Invalid address length', { expected: 64, got: body.length }); } return body; } } //# sourceMappingURL=aptos.js.map