@metaplex-foundation/mpl-token-metadata
Advanced tools
Comparing version 1.1.0 to 1.2.0
import { Borsh, StringPublicKey } from '@metaplex-foundation/mpl-core'; | ||
import { MetadataKey } from './constants'; | ||
declare type Args = { | ||
@@ -12,2 +13,11 @@ key: StringPublicKey; | ||
} | ||
declare type CollectionAuthorityRecordArgs = { | ||
bump: number; | ||
}; | ||
export declare class CollctionAuthorityRecord extends Borsh.Data<CollectionAuthorityRecordArgs> { | ||
static readonly SCHEMA: any; | ||
key: MetadataKey; | ||
bump: number; | ||
constructor(args: CollectionAuthorityRecordArgs); | ||
} | ||
export {}; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Collection = void 0; | ||
exports.CollctionAuthorityRecord = exports.Collection = void 0; | ||
const mpl_core_1 = require("@metaplex-foundation/mpl-core"); | ||
const constants_1 = require("./constants"); | ||
class Collection extends mpl_core_1.Borsh.Data { | ||
@@ -17,2 +18,14 @@ constructor(args) { | ||
]); | ||
class CollctionAuthorityRecord extends mpl_core_1.Borsh.Data { | ||
constructor(args) { | ||
super(args); | ||
this.key = constants_1.MetadataKey.CollectionAuthorityRecord; | ||
this.bump = args.bump; | ||
} | ||
} | ||
exports.CollctionAuthorityRecord = CollctionAuthorityRecord; | ||
CollctionAuthorityRecord.SCHEMA = CollctionAuthorityRecord.struct([ | ||
['key', 'u8'], | ||
['bump', 'u8'], | ||
]); | ||
//# sourceMappingURL=Collection.js.map |
@@ -7,3 +7,5 @@ export declare enum MetadataKey { | ||
MasterEditionV2 = 6, | ||
EditionMarker = 7 | ||
EditionMarker = 7, | ||
UseAuthorityRecord = 8, | ||
CollectionAuthorityRecord = 9 | ||
} | ||
@@ -10,0 +12,0 @@ export declare enum UseMethod { |
@@ -12,2 +12,4 @@ "use strict"; | ||
MetadataKey[MetadataKey["EditionMarker"] = 7] = "EditionMarker"; | ||
MetadataKey[MetadataKey["UseAuthorityRecord"] = 8] = "UseAuthorityRecord"; | ||
MetadataKey[MetadataKey["CollectionAuthorityRecord"] = 9] = "CollectionAuthorityRecord"; | ||
})(MetadataKey = exports.MetadataKey || (exports.MetadataKey = {})); | ||
@@ -14,0 +16,0 @@ var UseMethod; |
import { Borsh } from '@metaplex-foundation/mpl-core'; | ||
import { UseMethod } from '.'; | ||
declare type Args = { | ||
import { MetadataKey, UseMethod } from '.'; | ||
declare type UsesArgs = { | ||
useMethod: UseMethod; | ||
@@ -8,3 +8,3 @@ total: number; | ||
}; | ||
export declare class Uses extends Borsh.Data<Args> { | ||
export declare class Uses extends Borsh.Data<UsesArgs> { | ||
static readonly SCHEMA: any; | ||
@@ -14,4 +14,15 @@ useMethod: UseMethod; | ||
remaining: number; | ||
constructor(args: Args); | ||
constructor(args: UsesArgs); | ||
} | ||
declare type UseAuthorityRecordArgs = { | ||
allowedUses: number; | ||
bump: number; | ||
}; | ||
export declare class UseAuthorityRecord extends Borsh.Data<UseAuthorityRecordArgs> { | ||
static readonly SCHEMA: any; | ||
key: MetadataKey; | ||
allowedUses: number; | ||
bump: number; | ||
constructor(args: UseAuthorityRecordArgs); | ||
} | ||
export {}; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Uses = void 0; | ||
exports.UseAuthorityRecord = exports.Uses = void 0; | ||
const mpl_core_1 = require("@metaplex-foundation/mpl-core"); | ||
const _1 = require("."); | ||
class Uses extends mpl_core_1.Borsh.Data { | ||
@@ -19,2 +20,16 @@ constructor(args) { | ||
]); | ||
class UseAuthorityRecord extends mpl_core_1.Borsh.Data { | ||
constructor(args) { | ||
super(args); | ||
this.key = _1.MetadataKey.UseAuthorityRecord; | ||
this.allowedUses = args.allowedUses; | ||
this.bump = args.bump; | ||
} | ||
} | ||
exports.UseAuthorityRecord = UseAuthorityRecord; | ||
UseAuthorityRecord.SCHEMA = UseAuthorityRecord.struct([ | ||
['key', 'u8'], | ||
['allowedUses', 'u64'], | ||
['bump', 'u8'], | ||
]); | ||
//# sourceMappingURL=Uses.js.map |
@@ -5,3 +5,13 @@ import { PublicKey } from '@solana/web3.js'; | ||
static readonly PREFIX = "metadata"; | ||
static readonly EDITION = "edition"; | ||
static readonly USER = "user"; | ||
static readonly COLLECTION_AUTHORITY = "collection_authority"; | ||
static readonly BURN = "burn"; | ||
static readonly PUBKEY: PublicKey; | ||
static find_edition_account(mint: PublicKey, edition_number: string): Promise<[PublicKey, number]>; | ||
static find_master_edition_account(mint: PublicKey): Promise<[PublicKey, number]>; | ||
static find_metadata_account(mint: PublicKey): Promise<[PublicKey, number]>; | ||
static find_use_authority_account(mint: PublicKey, authority: PublicKey): Promise<[PublicKey, number]>; | ||
static find_collection_authority_account(mint: PublicKey, authority: PublicKey): Promise<[PublicKey, number]>; | ||
static find_program_as_burner_account(): Promise<[PublicKey, number]>; | ||
} |
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -7,6 +16,71 @@ exports.MetadataProgram = void 0; | ||
class MetadataProgram extends mpl_core_1.Program { | ||
static find_edition_account(mint, edition_number) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return web3_js_1.PublicKey.findProgramAddress([ | ||
Buffer.from(MetadataProgram.PREFIX, 'utf8'), | ||
MetadataProgram.PUBKEY.toBuffer(), | ||
mint.toBuffer(), | ||
Buffer.from(MetadataProgram.EDITION, 'utf8'), | ||
Buffer.from(edition_number, 'utf8'), | ||
], MetadataProgram.PUBKEY); | ||
}); | ||
} | ||
static find_master_edition_account(mint) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return web3_js_1.PublicKey.findProgramAddress([ | ||
Buffer.from(MetadataProgram.PREFIX, 'utf8'), | ||
MetadataProgram.PUBKEY.toBuffer(), | ||
mint.toBuffer(), | ||
Buffer.from(MetadataProgram.EDITION, 'utf8'), | ||
], MetadataProgram.PUBKEY); | ||
}); | ||
} | ||
static find_metadata_account(mint) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return web3_js_1.PublicKey.findProgramAddress([ | ||
Buffer.from(MetadataProgram.PREFIX, 'utf8'), | ||
MetadataProgram.PUBKEY.toBuffer(), | ||
mint.toBuffer(), | ||
], MetadataProgram.PUBKEY); | ||
}); | ||
} | ||
static find_use_authority_account(mint, authority) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return web3_js_1.PublicKey.findProgramAddress([ | ||
Buffer.from(MetadataProgram.PREFIX, 'utf8'), | ||
MetadataProgram.PUBKEY.toBuffer(), | ||
mint.toBuffer(), | ||
Buffer.from(MetadataProgram.USER, 'utf8'), | ||
authority.toBuffer(), | ||
], MetadataProgram.PUBKEY); | ||
}); | ||
} | ||
static find_collection_authority_account(mint, authority) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return web3_js_1.PublicKey.findProgramAddress([ | ||
Buffer.from(MetadataProgram.PREFIX, 'utf8'), | ||
MetadataProgram.PUBKEY.toBuffer(), | ||
mint.toBuffer(), | ||
Buffer.from(MetadataProgram.COLLECTION_AUTHORITY, 'utf8'), | ||
authority.toBuffer(), | ||
], MetadataProgram.PUBKEY); | ||
}); | ||
} | ||
static find_program_as_burner_account() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return web3_js_1.PublicKey.findProgramAddress([ | ||
Buffer.from(MetadataProgram.PREFIX, 'utf8'), | ||
MetadataProgram.PUBKEY.toBuffer(), | ||
Buffer.from(MetadataProgram.BURN, 'utf8'), | ||
], MetadataProgram.PUBKEY); | ||
}); | ||
} | ||
} | ||
exports.MetadataProgram = MetadataProgram; | ||
MetadataProgram.PREFIX = 'metadata'; | ||
MetadataProgram.EDITION = 'edition'; | ||
MetadataProgram.USER = 'user'; | ||
MetadataProgram.COLLECTION_AUTHORITY = 'collection_authority'; | ||
MetadataProgram.BURN = 'burn'; | ||
MetadataProgram.PUBKEY = new web3_js_1.PublicKey(mpl_core_1.config.programs.metadata); | ||
//# sourceMappingURL=MetadataProgram.js.map |
@@ -11,2 +11,9 @@ export * from './CreateMetadata'; | ||
export * from './VerifyCollection'; | ||
export * from './UnverifyCollection'; | ||
export * from './SignMetadata'; | ||
export * from './SetAndVerifyCollection'; | ||
export * from './ApproveUseAuthority'; | ||
export * from './RevokeUseAuthority'; | ||
export * from './ApproveCollectionAuthority'; | ||
export * from './RevokeCollectionAuthority'; | ||
export * from './Utilize'; |
@@ -23,3 +23,10 @@ "use strict"; | ||
__exportStar(require("./VerifyCollection"), exports); | ||
__exportStar(require("./UnverifyCollection"), exports); | ||
__exportStar(require("./SignMetadata"), exports); | ||
__exportStar(require("./SetAndVerifyCollection"), exports); | ||
__exportStar(require("./ApproveUseAuthority"), exports); | ||
__exportStar(require("./RevokeUseAuthority"), exports); | ||
__exportStar(require("./ApproveCollectionAuthority"), exports); | ||
__exportStar(require("./RevokeCollectionAuthority"), exports); | ||
__exportStar(require("./Utilize"), exports); | ||
//# sourceMappingURL=index.js.map |
@@ -9,2 +9,3 @@ import { Borsh, Transaction } from '@metaplex-foundation/mpl-core'; | ||
metadata: PublicKey; | ||
collectionAuthorityRecord?: PublicKey; | ||
collectionAuthority: PublicKey; | ||
@@ -11,0 +12,0 @@ collectionMint: PublicKey; |
@@ -19,37 +19,45 @@ "use strict"; | ||
const { feePayer } = options; | ||
const { metadata, collectionAuthority, collectionMint, collectionMetadata, collectionMasterEdition, } = params; | ||
const { metadata, collectionAuthority, collectionMint, collectionMetadata, collectionMasterEdition, collectionAuthorityRecord, } = params; | ||
const data = VerifyCollectionArgs.serialize(); | ||
const accounts = [ | ||
{ | ||
pubkey: metadata, | ||
isSigner: false, | ||
isWritable: true, | ||
}, | ||
{ | ||
pubkey: collectionAuthority, | ||
isSigner: true, | ||
isWritable: true, | ||
}, | ||
{ | ||
pubkey: feePayer, | ||
isSigner: true, | ||
isWritable: true, | ||
}, | ||
{ | ||
pubkey: collectionMint, | ||
isSigner: false, | ||
isWritable: false, | ||
}, | ||
{ | ||
pubkey: collectionMetadata, | ||
isSigner: false, | ||
isWritable: false, | ||
}, | ||
{ | ||
pubkey: collectionMasterEdition, | ||
isSigner: false, | ||
isWritable: false, | ||
}, | ||
]; | ||
if (collectionAuthorityRecord) { | ||
accounts.push({ | ||
pubkey: collectionAuthorityRecord, | ||
isSigner: false, | ||
isWritable: false, | ||
}); | ||
} | ||
this.add(new web3_js_1.TransactionInstruction({ | ||
keys: [ | ||
{ | ||
pubkey: metadata, | ||
isSigner: false, | ||
isWritable: true, | ||
}, | ||
{ | ||
pubkey: collectionAuthority, | ||
isSigner: true, | ||
isWritable: true, | ||
}, | ||
{ | ||
pubkey: feePayer, | ||
isSigner: true, | ||
isWritable: true, | ||
}, | ||
{ | ||
pubkey: collectionMint, | ||
isSigner: false, | ||
isWritable: false, | ||
}, | ||
{ | ||
pubkey: collectionMetadata, | ||
isSigner: false, | ||
isWritable: false, | ||
}, | ||
{ | ||
pubkey: collectionMasterEdition, | ||
isSigner: false, | ||
isWritable: false, | ||
}, | ||
], | ||
keys: accounts, | ||
programId: MetadataProgram_1.MetadataProgram.PUBKEY, | ||
@@ -56,0 +64,0 @@ data, |
@@ -35,3 +35,3 @@ import { Connection, Keypair, PublicKey } from '@solana/web3.js'; | ||
}>; | ||
export declare function createMasterEdition(connection: Connection, transactionHandler: TransactionHandler, payer: Keypair, args: DataV2): Promise<{ | ||
export declare function createMasterEdition(connection: Connection, transactionHandler: TransactionHandler, payer: Keypair, args: DataV2, maxSupply: number): Promise<{ | ||
mint: spl.Token; | ||
@@ -38,0 +38,0 @@ metadata: PublicKey; |
@@ -112,3 +112,3 @@ "use strict"; | ||
exports.mintAndCreateMetadataV2 = mintAndCreateMetadataV2; | ||
function createMasterEdition(connection, transactionHandler, payer, args) { | ||
function createMasterEdition(connection, transactionHandler, payer, args, maxSupply) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
@@ -123,3 +123,3 @@ const { mint, metadata } = yield mintAndCreateMetadataV2(connection, transactionHandler, payer, args); | ||
mintAuthority: payer.publicKey, | ||
maxSupply: new bn_js_1.default(1), | ||
maxSupply: new bn_js_1.default(maxSupply), | ||
}); | ||
@@ -126,0 +126,0 @@ const createTxDetails = yield transactionHandler.sendAndConfirmTransaction(createMev3, [], { |
@@ -22,17 +22,4 @@ "use strict"; | ||
const accounts_1 = require("../src/accounts"); | ||
const transactions_1 = require("src/transactions"); | ||
(0, utils_1.killStuckProcess)(); | ||
function createCollection(connection, transactionHandler, payer) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const initMetadataData = new mpl_token_metadata_1.DataV2({ | ||
uri: utils_1.URI, | ||
name: utils_1.NAME, | ||
symbol: utils_1.SYMBOL, | ||
sellerFeeBasisPoints: utils_1.SELLER_FEE_BASIS_POINTS, | ||
creators: null, | ||
collection: null, | ||
uses: null, | ||
}); | ||
return yield (0, actions_1.createMasterEdition)(connection, transactionHandler, payer, initMetadataData); | ||
}); | ||
} | ||
(0, tape_1.default)('verify-collection', (t) => __awaiter(void 0, void 0, void 0, function* () { | ||
@@ -43,3 +30,3 @@ const payer = web3_js_1.Keypair.generate(); | ||
yield (0, amman_1.airdrop)(connection, payer.publicKey, 2); | ||
const collectionNft = yield createCollection(connection, transactionHandler, payer); | ||
const collectionNft = yield (0, utils_1.createCollection)(connection, transactionHandler, payer); | ||
const initMetadataData = new mpl_token_metadata_1.DataV2({ | ||
@@ -54,3 +41,3 @@ uri: utils_1.URI, | ||
}); | ||
const collectionMemberNft = yield (0, actions_1.createMasterEdition)(connection, transactionHandler, payer, initMetadataData); | ||
const collectionMemberNft = yield (0, actions_1.createMasterEdition)(connection, transactionHandler, payer, initMetadataData, 0); | ||
console.log('collectionMemberNft', collectionMemberNft.metadata.toBase58()); | ||
@@ -72,2 +59,193 @@ const updatedMetadataBeforeVerification = yield (0, utils_1.getMetadataData)(connection, collectionMemberNft.metadata); | ||
})); | ||
(0, tape_1.default)('set-and-verify-collection', (t) => __awaiter(void 0, void 0, void 0, function* () { | ||
const payer = web3_js_1.Keypair.generate(); | ||
const connection = new web3_js_1.Connection(utils_1.connectionURL, 'confirmed'); | ||
const transactionHandler = new amman_1.PayerTransactionHandler(connection, payer); | ||
yield (0, amman_1.airdrop)(connection, payer.publicKey, 2); | ||
const collectionNft = yield (0, utils_1.createCollection)(connection, transactionHandler, payer); | ||
const initMetadataData = new mpl_token_metadata_1.DataV2({ | ||
uri: utils_1.URI, | ||
name: utils_1.NAME, | ||
symbol: utils_1.SYMBOL, | ||
sellerFeeBasisPoints: utils_1.SELLER_FEE_BASIS_POINTS, | ||
creators: null, | ||
collection: null, | ||
uses: null, | ||
}); | ||
const collectionMemberNft = yield (0, actions_1.createMasterEdition)(connection, transactionHandler, payer, initMetadataData, 0); | ||
const updatedMetadataBeforeVerification = yield (0, utils_1.getMetadataData)(connection, collectionMemberNft.metadata); | ||
t.not(updatedMetadataBeforeVerification.collection, 'collection should be null'); | ||
const collectionVerifyCollectionTransaction = new transactions_1.SetAndVerifyCollectionCollection({ feePayer: payer.publicKey }, { | ||
metadata: collectionMemberNft.metadata, | ||
collectionAuthority: payer.publicKey, | ||
updateAuthority: payer.publicKey, | ||
collectionMint: collectionNft.mint.publicKey, | ||
collectionMetadata: collectionNft.metadata, | ||
collectionMasterEdition: collectionNft.masterEditionPubkey, | ||
}); | ||
const txDetails = yield transactionHandler.sendAndConfirmTransaction(collectionVerifyCollectionTransaction, [payer], { skipPreflight: true }); | ||
(0, utils_1.logDebug)(txDetails.txSummary.logMessages.join('\n')); | ||
const updatedMetadataAfterVerification = yield (0, utils_1.getMetadataData)(connection, collectionMemberNft.metadata); | ||
t.ok(updatedMetadataAfterVerification.collection, 'collection should be not null'); | ||
t.ok(updatedMetadataAfterVerification.collection.verified, 'collection should be verified'); | ||
})); | ||
(0, tape_1.default)('Delegated Authority', (t) => { | ||
t.test('Fail: Verify Collection', (t) => __awaiter(void 0, void 0, void 0, function* () { | ||
const payer = web3_js_1.Keypair.generate(); | ||
const connection = new web3_js_1.Connection(utils_1.connectionURL, 'confirmed'); | ||
const transactionHandler = new amman_1.PayerTransactionHandler(connection, payer); | ||
yield (0, amman_1.airdrop)(connection, payer.publicKey, 2); | ||
const collectionNft = yield (0, utils_1.createCollection)(connection, transactionHandler, payer); | ||
const initMetadataData = new mpl_token_metadata_1.DataV2({ | ||
uri: utils_1.URI, | ||
name: utils_1.NAME, | ||
symbol: utils_1.SYMBOL, | ||
sellerFeeBasisPoints: utils_1.SELLER_FEE_BASIS_POINTS, | ||
creators: null, | ||
collection: new accounts_1.Collection({ key: collectionNft.mint.publicKey.toBase58(), verified: false }), | ||
uses: null, | ||
}); | ||
const collectionMemberNft = yield (0, actions_1.createMasterEdition)(connection, transactionHandler, payer, initMetadataData, 0); | ||
const updatedMetadataBeforeVerification = yield (0, utils_1.getMetadataData)(connection, collectionMemberNft.metadata); | ||
t.ok(updatedMetadataBeforeVerification.collection, 'collection should be null'); | ||
t.false(updatedMetadataBeforeVerification.collection.verified, 'collection cant be verified'); | ||
const delegatedAuthority = web3_js_1.Keypair.generate(); | ||
yield (0, amman_1.airdrop)(connection, delegatedAuthority.publicKey, 2); | ||
const dARecord = yield mpl_token_metadata_1.MetadataProgram.find_collection_authority_account(collectionNft.mint.publicKey, delegatedAuthority.publicKey); | ||
const collectionVerifyCollectionTransaction = new mpl_token_metadata_1.VerifyCollection({ feePayer: payer.publicKey }, { | ||
metadata: collectionMemberNft.metadata, | ||
collectionAuthority: delegatedAuthority.publicKey, | ||
collectionMint: collectionNft.mint.publicKey, | ||
collectionMetadata: collectionNft.metadata, | ||
collectionMasterEdition: collectionNft.masterEditionPubkey, | ||
collectionAuthorityRecord: dARecord[0], | ||
}); | ||
const txDetails = yield transactionHandler.sendAndConfirmTransaction(collectionVerifyCollectionTransaction, [delegatedAuthority], { skipPreflight: true }); | ||
(0, utils_1.logDebug)(txDetails.txSummary.logMessages.join('\n')); | ||
t.deepEqual(txDetails.txSummary.err, { InstructionError: [0, { Custom: 81 }] }, 'Collection Update Authority is invalid'); | ||
})); | ||
t.test('Fail: Set and Verify Collection', (t) => __awaiter(void 0, void 0, void 0, function* () { | ||
const payer = web3_js_1.Keypair.generate(); | ||
const connection = new web3_js_1.Connection(utils_1.connectionURL, 'confirmed'); | ||
const transactionHandler = new amman_1.PayerTransactionHandler(connection, payer); | ||
yield (0, amman_1.airdrop)(connection, payer.publicKey, 2); | ||
const collectionNft = yield (0, utils_1.createCollection)(connection, transactionHandler, payer); | ||
const initMetadataData = new mpl_token_metadata_1.DataV2({ | ||
uri: utils_1.URI, | ||
name: utils_1.NAME, | ||
symbol: utils_1.SYMBOL, | ||
sellerFeeBasisPoints: utils_1.SELLER_FEE_BASIS_POINTS, | ||
creators: null, | ||
collection: null, | ||
uses: null, | ||
}); | ||
const collectionMemberNft = yield (0, actions_1.createMasterEdition)(connection, transactionHandler, payer, initMetadataData, 0); | ||
const updatedMetadataBeforeVerification = yield (0, utils_1.getMetadataData)(connection, collectionMemberNft.metadata); | ||
t.notOk(updatedMetadataBeforeVerification.collection, 'collection should be null'); | ||
const delegatedAuthority = web3_js_1.Keypair.generate(); | ||
yield (0, amman_1.airdrop)(connection, delegatedAuthority.publicKey, 2); | ||
const dARecord = yield mpl_token_metadata_1.MetadataProgram.find_collection_authority_account(collectionNft.mint.publicKey, delegatedAuthority.publicKey); | ||
const collectionVerifyCollectionTransaction = new transactions_1.SetAndVerifyCollectionCollection({ feePayer: delegatedAuthority.publicKey }, { | ||
metadata: collectionMemberNft.metadata, | ||
collectionAuthority: delegatedAuthority.publicKey, | ||
updateAuthority: payer.publicKey, | ||
collectionMint: collectionNft.mint.publicKey, | ||
collectionMetadata: collectionNft.metadata, | ||
collectionMasterEdition: collectionNft.masterEditionPubkey, | ||
collectionAuthorityRecord: dARecord[0], | ||
}); | ||
const txDetails = yield transactionHandler.sendAndConfirmTransaction(collectionVerifyCollectionTransaction, [delegatedAuthority], { skipPreflight: true }); | ||
(0, utils_1.logDebug)(txDetails.txSummary.logMessages.join('\n')); | ||
t.deepEqual(txDetails.txSummary.err, { InstructionError: [0, { Custom: 81 }] }, 'Collection Update Authority is invalid'); | ||
})); | ||
t.test('Success: Verify Collection', (t) => __awaiter(void 0, void 0, void 0, function* () { | ||
const payer = web3_js_1.Keypair.generate(); | ||
const connection = new web3_js_1.Connection(utils_1.connectionURL, 'confirmed'); | ||
const transactionHandler = new amman_1.PayerTransactionHandler(connection, payer); | ||
yield (0, amman_1.airdrop)(connection, payer.publicKey, 2); | ||
const collectionNft = yield (0, utils_1.createCollection)(connection, transactionHandler, payer); | ||
const initMetadataData = new mpl_token_metadata_1.DataV2({ | ||
uri: utils_1.URI, | ||
name: utils_1.NAME, | ||
symbol: utils_1.SYMBOL, | ||
sellerFeeBasisPoints: utils_1.SELLER_FEE_BASIS_POINTS, | ||
creators: null, | ||
collection: new accounts_1.Collection({ key: collectionNft.mint.publicKey.toBase58(), verified: false }), | ||
uses: null, | ||
}); | ||
const collectionMemberNft = yield (0, actions_1.createMasterEdition)(connection, transactionHandler, payer, initMetadataData, 0); | ||
const updatedMetadataBeforeVerification = yield (0, utils_1.getMetadataData)(connection, collectionMemberNft.metadata); | ||
t.ok(updatedMetadataBeforeVerification.collection, 'collection should not be null'); | ||
t.false(updatedMetadataBeforeVerification.collection.verified, 'collection cant be verified'); | ||
const delegatedAuthority = web3_js_1.Keypair.generate(); | ||
yield (0, amman_1.airdrop)(connection, delegatedAuthority.publicKey, 2); | ||
const dARecord = yield mpl_token_metadata_1.MetadataProgram.find_collection_authority_account(collectionNft.mint.publicKey, delegatedAuthority.publicKey); | ||
const approveTransaction = new mpl_token_metadata_1.ApproveCollectionAuthority({ feePayer: payer.publicKey }, { | ||
collectionAuthorityRecord: dARecord[0], | ||
newCollectionAuthority: delegatedAuthority.publicKey, | ||
updateAuthority: payer.publicKey, | ||
metadata: collectionNft.metadata, | ||
mint: collectionNft.mint.publicKey, | ||
}); | ||
const approveTxnDetails = yield transactionHandler.sendAndConfirmTransaction(approveTransaction, [payer], { skipPreflight: true }); | ||
(0, utils_1.logDebug)(approveTxnDetails.txSummary.logMessages.join('\n')); | ||
const collectionVerifyCollectionTransaction = new mpl_token_metadata_1.VerifyCollection({ feePayer: payer.publicKey }, { | ||
metadata: collectionMemberNft.metadata, | ||
collectionAuthority: delegatedAuthority.publicKey, | ||
collectionMint: collectionNft.mint.publicKey, | ||
collectionMetadata: collectionNft.metadata, | ||
collectionMasterEdition: collectionNft.masterEditionPubkey, | ||
collectionAuthorityRecord: dARecord[0], | ||
}); | ||
const txDetails = yield transactionHandler.sendAndConfirmTransaction(collectionVerifyCollectionTransaction, [delegatedAuthority], { skipPreflight: true }); | ||
(0, utils_1.logDebug)(txDetails.txSummary.logMessages.join('\n')); | ||
const updatedMetadataAfterVerification = yield (0, utils_1.getMetadataData)(connection, collectionMemberNft.metadata); | ||
t.ok(updatedMetadataAfterVerification.collection, 'collection should not be null'); | ||
t.true(updatedMetadataAfterVerification.collection.verified, 'collection is verified'); | ||
})); | ||
t.test('Success: Set and Verify Collection', (t) => __awaiter(void 0, void 0, void 0, function* () { | ||
const payer = web3_js_1.Keypair.generate(); | ||
const connection = new web3_js_1.Connection(utils_1.connectionURL, 'confirmed'); | ||
const transactionHandler = new amman_1.PayerTransactionHandler(connection, payer); | ||
yield (0, amman_1.airdrop)(connection, payer.publicKey, 2); | ||
const collectionNft = yield (0, utils_1.createCollection)(connection, transactionHandler, payer); | ||
const initMetadataData = new mpl_token_metadata_1.DataV2({ | ||
uri: utils_1.URI, | ||
name: utils_1.NAME, | ||
symbol: utils_1.SYMBOL, | ||
sellerFeeBasisPoints: utils_1.SELLER_FEE_BASIS_POINTS, | ||
creators: null, | ||
collection: null, | ||
uses: null, | ||
}); | ||
const collectionMemberNft = yield (0, actions_1.createMasterEdition)(connection, transactionHandler, payer, initMetadataData, 0); | ||
const updatedMetadataBeforeVerification = yield (0, utils_1.getMetadataData)(connection, collectionMemberNft.metadata); | ||
t.not(updatedMetadataBeforeVerification.collection, 'collection should be null'); | ||
const delegatedAuthority = web3_js_1.Keypair.generate(); | ||
yield (0, amman_1.airdrop)(connection, delegatedAuthority.publicKey, 2); | ||
const dARecord = yield mpl_token_metadata_1.MetadataProgram.find_collection_authority_account(collectionNft.mint.publicKey, delegatedAuthority.publicKey); | ||
const approveTransaction = new mpl_token_metadata_1.ApproveCollectionAuthority({ feePayer: payer.publicKey }, { | ||
collectionAuthorityRecord: dARecord[0], | ||
newCollectionAuthority: delegatedAuthority.publicKey, | ||
updateAuthority: payer.publicKey, | ||
metadata: collectionNft.metadata, | ||
mint: collectionNft.mint.publicKey, | ||
}); | ||
const approveTxnDetails = yield transactionHandler.sendAndConfirmTransaction(approveTransaction, [payer], { skipPreflight: true }); | ||
(0, utils_1.logDebug)(approveTxnDetails.txSummary.logMessages.join('\n')); | ||
const collectionVerifyCollectionTransaction = new transactions_1.SetAndVerifyCollectionCollection({ feePayer: delegatedAuthority.publicKey }, { | ||
metadata: collectionMemberNft.metadata, | ||
collectionAuthority: delegatedAuthority.publicKey, | ||
updateAuthority: payer.publicKey, | ||
collectionMint: collectionNft.mint.publicKey, | ||
collectionMetadata: collectionNft.metadata, | ||
collectionMasterEdition: collectionNft.masterEditionPubkey, | ||
collectionAuthorityRecord: dARecord[0], | ||
}); | ||
yield transactionHandler.sendAndConfirmTransaction(collectionVerifyCollectionTransaction, [delegatedAuthority], { skipPreflight: true }); | ||
const updatedMetadataAfterVerification = yield (0, utils_1.getMetadataData)(connection, collectionMemberNft.metadata); | ||
t.ok(updatedMetadataAfterVerification.collection, 'collection should not be null'); | ||
t.true(updatedMetadataAfterVerification.collection.verified, 'collection is verified'); | ||
})); | ||
}); | ||
//# sourceMappingURL=create-and-verify-collection.test.js.map |
@@ -88,2 +88,56 @@ "use strict"; | ||
})); | ||
(0, tape_1.default)('create-metadata-account-v2: success', (t) => __awaiter(void 0, void 0, void 0, function* () { | ||
const payer = web3_js_1.Keypair.generate(); | ||
(0, address_labels_1.addLabel)('create:payer', payer); | ||
const connection = new web3_js_1.Connection(utils_1.connectionURL, 'confirmed'); | ||
const transactionHandler = new amman_1.PayerTransactionHandler(connection, payer); | ||
yield (0, amman_1.airdrop)(connection, payer.publicKey, 2); | ||
const { mint, createMintTx } = yield new amman_1.Actions(connection).createMintAccount(payer.publicKey); | ||
const mintRes = yield transactionHandler.sendAndConfirmTransaction(createMintTx, [mint], amman_1.defaultSendOptions); | ||
(0, address_labels_1.addLabel)('create:mint', mint); | ||
(0, amman_1.assertConfirmedTransaction)(t, mintRes.txConfirmed); | ||
const initMetadataData = new mpl_token_metadata_1.DataV2({ | ||
uri: URI, | ||
name: NAME, | ||
symbol: SYMBOL, | ||
sellerFeeBasisPoints: SELLER_FEE_BASIS_POINTS, | ||
creators: null, | ||
collection: null, | ||
uses: null, | ||
}); | ||
const { createTxDetails, metadata } = yield (0, actions_1.createMetadataV2)({ | ||
transactionHandler, | ||
publicKey: payer.publicKey, | ||
mint: mint.publicKey, | ||
metadataData: initMetadataData, | ||
updateAuthority: payer.publicKey, | ||
}); | ||
(0, address_labels_1.addLabel)('create:metadata', metadata); | ||
(0, utils_2.logDebug)(createTxDetails.txSummary.logMessages.join('\n')); | ||
(0, amman_1.assertTransactionSummary)(t, createTxDetails.txSummary, { | ||
fee: 5000, | ||
msgRx: [/Program.+metaq/i, /Instruction.+ Create Metadata Accounts/i], | ||
}); | ||
const metadataAccount = yield connection.getAccountInfo(metadata); | ||
(0, utils_2.logDebug)({ | ||
metadataAccountOwner: metadataAccount.owner.toBase58(), | ||
metadataAccountDataBytes: metadataAccount.data.byteLength, | ||
}); | ||
const metadataData = mpl_token_metadata_1.MetadataData.deserialize(metadataAccount.data); | ||
(0, spok_1.default)(t, metadataData, { | ||
$topic: 'metadataData', | ||
key: mpl_token_metadata_1.MetadataKey.MetadataV1, | ||
updateAuthority: (0, address_labels_1.isKeyOf)(payer), | ||
mint: (0, address_labels_1.isKeyOf)(mint), | ||
data: { | ||
name: NAME, | ||
symbol: SYMBOL, | ||
uri: URI, | ||
sellerFeeBasisPoints: SELLER_FEE_BASIS_POINTS, | ||
}, | ||
primarySaleHappened: 0, | ||
isMutable: 1, | ||
tokenStandard: mpl_token_metadata_1.TokenStandard.FungibleAsset, | ||
}); | ||
})); | ||
//# sourceMappingURL=create-metadata-account.test.js.map |
@@ -0,2 +1,5 @@ | ||
/// <reference types="@solana/spl-token" /> | ||
import { Connection, Keypair } from '@solana/web3.js'; | ||
import debug from 'debug'; | ||
import { TransactionHandler } from '@metaplex-foundation/amman'; | ||
export * from './address-labels'; | ||
@@ -18,1 +21,7 @@ export * from './metadata'; | ||
export declare function killStuckProcess(): void; | ||
export declare function createCollection(connection: Connection, transactionHandler: TransactionHandler, payer: Keypair): Promise<{ | ||
mint: import("@solana/spl-token").Token; | ||
metadata: import("@solana/web3.js").PublicKey; | ||
masterEditionPubkey: import("@solana/web3.js").PublicKey; | ||
createTxDetails: import("@metaplex-foundation/amman").ConfirmedTransactionDetails; | ||
}>; |
@@ -12,2 +12,11 @@ "use strict"; | ||
}; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
@@ -17,3 +26,3 @@ return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.killStuckProcess = exports.dump = exports.connectionURL = exports.DEVNET = exports.programIds = exports.logTrace = exports.logDebug = exports.logInfo = exports.logError = void 0; | ||
exports.createCollection = exports.killStuckProcess = exports.dump = exports.connectionURL = exports.DEVNET = exports.programIds = exports.logTrace = exports.logDebug = exports.logInfo = exports.logError = void 0; | ||
const web3_js_1 = require("@solana/web3.js"); | ||
@@ -24,2 +33,5 @@ const util_1 = require("util"); | ||
const amman_1 = require("@metaplex-foundation/amman"); | ||
const accounts_1 = require("../../src/accounts"); | ||
const metadata_1 = require("./metadata"); | ||
const actions_1 = require("../actions"); | ||
__exportStar(require("./address-labels"), exports); | ||
@@ -47,2 +59,17 @@ __exportStar(require("./metadata"), exports); | ||
exports.killStuckProcess = killStuckProcess; | ||
function createCollection(connection, transactionHandler, payer) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const initMetadataData = new accounts_1.DataV2({ | ||
uri: metadata_1.URI, | ||
name: metadata_1.NAME, | ||
symbol: metadata_1.SYMBOL, | ||
sellerFeeBasisPoints: metadata_1.SELLER_FEE_BASIS_POINTS, | ||
creators: null, | ||
collection: null, | ||
uses: null, | ||
}); | ||
return yield (0, actions_1.createMasterEdition)(connection, transactionHandler, payer, initMetadataData, 0); | ||
}); | ||
} | ||
exports.createCollection = createCollection; | ||
//# sourceMappingURL=index.js.map |
@@ -31,3 +31,3 @@ "use strict"; | ||
(0, address_labels_1.addLabel)('payer', payer); | ||
const connection = new web3_js_1.Connection(_1.connectionURL, 'confirmed'); | ||
const connection = new web3_js_1.Connection(_1.connectionURL, 'singleGossip'); | ||
const transactionHandler = new amman_1.PayerTransactionHandler(connection, payer); | ||
@@ -34,0 +34,0 @@ yield (0, amman_1.airdrop)(connection, payer.publicKey, 2); |
{ | ||
"name": "@metaplex-foundation/mpl-token-metadata", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"description": "MPL Token Metadata JavaScript API.", | ||
@@ -12,9 +12,9 @@ "main": "dist/src/mpl-token-metadata.js", | ||
"prepublishOnly": "yarn check:publish-ready", | ||
"postpublish": "git push origin && git push origin --tags", | ||
"postpublish": "git push origin && git push origin --tags 2>/dev/null", | ||
"build:docs": "typedoc", | ||
"build": "rimraf dist && tsc -p tsconfig.json", | ||
"pretest": "yarn build", | ||
"amman:start": "DEBUG=\"amman*\" amman validator", | ||
"amman:start": "DEBUG=\"*\" amman validator", | ||
"amman:stop": "pkill solana-test-validator", | ||
"test": "tape ./dist/test/*.test.js", | ||
"test": "esr ./test/*.test.ts", | ||
"lint": "eslint \"{src,test}/**/*.ts\" --format stylish", | ||
@@ -54,2 +54,3 @@ "fix:lint": "yarn lint --fix", | ||
"debug": "^4.3.3", | ||
"esbuild-runner": "2.2.1", | ||
"eslint": "^8.3.0", | ||
@@ -61,2 +62,2 @@ "rimraf": "^3.0.2", | ||
} | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
223358
116
3444
0
11