@silvana-one/nft
Version:
Mina NFT library
62 lines • 2.4 kB
JavaScript
import { __decorate, __metadata } from "tslib";
import { AccountUpdate, Bool, method, PublicKey, SmartContract, state, State, Permissions, } from "o1js";
import { TransferExtendedParams } from "./types.js";
export { NFTStandardApproval, };
/**
* The **NFTStandardApproval** contract is the default implementation of the `NFTApprovalBase` interface.
*/
class NFTStandardApproval extends SmartContract {
constructor() {
super(...arguments);
/**
* The public key of the contract's administrator.
* This account has the authority to perform administrative actions such as pausing the contract or upgrading the verification key.
*/
this.admin = State();
}
/**
* Deploys the contract with initial settings.
* @param props - Deployment properties including admin, upgradeAuthority, uri, canPause, and isPaused.
*/
async deploy(props) {
await super.deploy(props);
this.admin.set(props.admin);
this.account.zkappUri.set(props.uri);
this.account.permissions.set({
...Permissions.default(),
setVerificationKey: Permissions.VerificationKey.signature(),
setPermissions: Permissions.impossible(),
});
}
/**
* Ensures that the transaction is authorized by the contract owner.
* @returns A signed `AccountUpdate` from the admin.
*/
async ensureOwnerSignature() {
const admin = this.admin.getAndRequireEquals();
const adminUpdate = AccountUpdate.createSigned(admin);
adminUpdate.body.useFullCommitment = Bool(true); // Prevent memo and fee change
return adminUpdate;
}
/**
* Determines if an NFT can be transferred.
*
* @param params - The transfer details.
* @returns A `Promise` resolving to a `Bool` indicating whether the transfer is allowed.
*/
async canTransfer(params) {
await this.ensureOwnerSignature();
return Bool(true);
}
}
__decorate([
state(PublicKey),
__metadata("design:type", Object)
], NFTStandardApproval.prototype, "admin", void 0);
__decorate([
method.returns(Bool),
__metadata("design:type", Function),
__metadata("design:paramtypes", [TransferExtendedParams]),
__metadata("design:returntype", Promise)
], NFTStandardApproval.prototype, "canTransfer", null);
//# sourceMappingURL=approval.js.map