@silvana-one/nft
Version:
Mina NFT library
101 lines (100 loc) • 3.71 kB
JavaScript
import { __decorate, __metadata } from "tslib";
import { AccountUpdate, Bool, method, PublicKey, SmartContract, state, State, Permissions, VerificationKey, } from "o1js";
import { TransferExtendedParams } from "./types.js";
export { NFTStandardOwner, };
/**
* The **NFTStandardOwner** contract is the default implementation of the `NFTOwnerBase` interface.
*/
class NFTStandardOwner 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;
}
async canTransfer(params) {
await this.ensureOwnerSignature();
return Bool(true);
}
async canPause(collection, nft) {
await this.ensureOwnerSignature();
return Bool(true);
}
async canResume(collection, nft) {
await this.ensureOwnerSignature();
return Bool(true);
}
async canChangeVerificationKey(collection, nft, vk) {
await this.ensureOwnerSignature();
return Bool(true);
}
async canApproveAddress(collection, nft, approved) {
await this.ensureOwnerSignature();
return Bool(true);
}
}
__decorate([
state(PublicKey),
__metadata("design:type", Object)
], NFTStandardOwner.prototype, "admin", void 0);
__decorate([
method.returns(Bool),
__metadata("design:type", Function),
__metadata("design:paramtypes", [TransferExtendedParams]),
__metadata("design:returntype", Promise)
], NFTStandardOwner.prototype, "canTransfer", null);
__decorate([
method.returns(Bool),
__metadata("design:type", Function),
__metadata("design:paramtypes", [PublicKey, PublicKey]),
__metadata("design:returntype", Promise)
], NFTStandardOwner.prototype, "canPause", null);
__decorate([
method.returns(Bool),
__metadata("design:type", Function),
__metadata("design:paramtypes", [PublicKey, PublicKey]),
__metadata("design:returntype", Promise)
], NFTStandardOwner.prototype, "canResume", null);
__decorate([
method.returns(Bool),
__metadata("design:type", Function),
__metadata("design:paramtypes", [PublicKey,
PublicKey,
VerificationKey]),
__metadata("design:returntype", Promise)
], NFTStandardOwner.prototype, "canChangeVerificationKey", null);
__decorate([
method.returns(Bool),
__metadata("design:type", Function),
__metadata("design:paramtypes", [PublicKey,
PublicKey,
PublicKey]),
__metadata("design:returntype", Promise)
], NFTStandardOwner.prototype, "canApproveAddress", null);
//# sourceMappingURL=owner.js.map