@silvana-one/nft
Version:
Mina NFT library
39 lines • 1.29 kB
JavaScript
import { PublicKey, Poseidon } from "o1js";
export { MinaAddress };
/**
/**
* The `MinaAddress` class represents a Mina address in the form of a Merkle tree. The address is converted to its
* hash and stored as a leaf in the Merkle tree. The root of the tree can be used as a compact representation
* of the address data in cryptographic proofs.
*/
class MinaAddress {
/**
* Constructs a new `MinaAddress` instance by creating a Merkle tree from the given address.
* The address is converted to its hash and stored as a leaf in the tree.
*
* @param address - The address to be represented.
* @throws Will throw an error if the address is not a valid Mina address.
*/
constructor(address) {
this.address =
typeof address === "string" ? PublicKey.fromBase58(address) : address;
this.hash = Poseidon.hashPacked(PublicKey, this.address);
}
/**
* Returns the original address.
*
* @returns The public key.
*/
toPublicKey() {
return this.address;
}
/**
* Returns the base58 representation of the address.
*
* @returns The base58 representation of the address.
*/
toString() {
return this.address.toBase58();
}
}
//# sourceMappingURL=address.js.map