Options
All
  • Public
  • Public/Protected
  • All
Menu

@nftstorage/metaplex-auth

Index

Type aliases

EncodedCar: { car: <internal>.CarReader; cid: CID }

Type declaration

ServiceContext: { auth: AuthContext; endpoint?: URL }

Information required to reach the NFT.Storage service and prepare upload tokens.

Type declaration

Signer: (message: Uint8Array) => Promise<Uint8Array>

Type declaration

    • (message: Uint8Array): Promise<Uint8Array>
    • Parameters

      • message: Uint8Array

      Returns Promise<Uint8Array>

SolanaCluster: string

Variables

Blob: { prototype: Blob }

Type declaration

  • prototype: Blob
File: { prototype: <internal>.File }

Type declaration

TagChain: "chain" = 'chain'

Request tag indicating what blockchain will be used to mint. Currently, the value will always be set to "solana" and cannot be overridden by the user.

TagMintingAgent: "mintingAgent" = 'mintingAgent'

Request tag indicating which "user agent" or tool is being used to prepare the upload. This should be set to a string that includes the name of the tool or platform.

Projects using this library are free to choose their own value for this tag, however you should avoid changing the name over time, unless the project itself changes names (for example, due to a community fork or re-branding).

For personal projects or individuals creating tools that are not affiliated with a public platform, please set the value to a URL for your code repository. If your code is not yet public, please create a repository containing a description of the project and links to its public-facing interface.

Examples of suitable values:

  • "metaplex/candy-machine-cli"
  • "metaplex/js-sdk"
  • "magiceden/mint-authority"
  • "https://github.com/samuelvanderwaal/metaboss"
TagMintingAgentVersion: "agentVersion" = 'agentVersion'

Optional request tag indicating which version of the "minting agent" was used to prepare the request. This may contain arbitrary text, as each project may have their own versioning scheme.

TagSolanaCluster: "solanaCluster" = 'solanaCluster'

Request tag indicating which Solana cluster will be used to mint.

Currently this library will accept any string value, however it is strongly recommended that you use one of these "canonical" values: "devnet", "mainnet-beta", "testnet". This may be enforced by the backend at a later date.

metadataSchema: JSONSchemaType<MetaplexMetadata> = ...
validateMetadata: ValidateFunction<MetaplexMetadata> = ...

Validator function for Metaplex NFT metadata objects. Returns true if metadata is valid.

Can be used as a TypeScript type guard - if validateMetadata(someObject) returns true, someObject can safely be treated as an instance of MetaplexMetadata.

Functions

  • MetaplexAuthWithSecretKey(privkey: Uint8Array, opts: { agentVersion?: string; mintingAgent: string; solanaCluster?: string }): AuthContext
  • Parameters

    • privkey: Uint8Array
    • opts: { agentVersion?: string; mintingAgent: string; solanaCluster?: string }
      • Optional agentVersion?: string
      • mintingAgent: string
      • Optional solanaCluster?: string

    Returns AuthContext

  • MetaplexAuthWithSigner(signMessage: Signer, publicKey: Uint8Array, opts: { agentVersion?: string; mintingAgent: string; solanaCluster?: string }): AuthContext
  • Parameters

    • signMessage: Signer
    • publicKey: Uint8Array
    • opts: { agentVersion?: string; mintingAgent: string; solanaCluster?: string }
      • Optional agentVersion?: string
      • mintingAgent: string
      • Optional solanaCluster?: string

    Returns AuthContext

  • keyDID(pubkey: Uint8Array): string
  • loadNFTFromFilesystem(metadataFilePath: string, imageFilePath?: string, opts?: { blockstore?: <internal>.Blockstore; gatewayHost?: string; validateSchema?: boolean }): Promise<PackagedNFT>
  • Loads a Metaplex NFT from the filesystem, including metadata json, main image, and any additional files referenced in the metadata.

    Loads Metaplex NFT metadata JSON from metadataFilePath, using the image located at imageFilePath. If imageFilePath is not provided, attempts to find the image in the following way:

    • If the metadata JSON object's image field contains the path to a file and the file exists, use it
    • Otherwise, take the filename of the metadata file (e.g. 1.json) and look for a file with the same basename and a .png extension (e.g. 1.png).

    If no image file can be found, the returned promise will reject with an Error.

    In addition to the image field, if the animation_url contains a valid file path, the file will be uploaded to NFT.Storage, and animation_url will be set to an IPFS HTTP gateway link to the content.

    Entries in properties.files that contain valid file paths as their uri value will also be uploaded to NFT.Storage, and each file will have two entries in the final metadata's properties.files array. One entry contains an HTTP gateway URL as the uri, with the cdn field set to true, while the other contains an ipfs:// URI, with cdn set to false. This preserves the location-independent "canonical" IPFS URI in the blockchain-linked record, while signalling to HTTP-only clients that they can use the cdn variant.

    All file paths contained in the metadata should be relative to the directory containing the metadata file.

    Note that this function does NOT store anything with NFT.Storage. To store the returned PackagedNFT object, see NFTStorageMetaplexor.storePreparedNFT, or use NFTStorageMetaplexor.storeNFTFromFilesystem, which calls this function and stores the result.

    This function is only available on node.js and will throw if invoked from a browser runtime.

    Parameters

    • metadataFilePath: string

      path to a JSON file containing Metaplex NFT metadata

    • Optional imageFilePath: string

      path to an image to be used as the primary image content for the NFT. If not provided, the image will be located as described above.

    • opts: { blockstore?: <internal>.Blockstore; gatewayHost?: string; validateSchema?: boolean } = {}
      • Optional blockstore?: <internal>.Blockstore

        a Blockstore instance to use when packing objects into CARs. If not provided, a new temporary Blockstore will be created.

      • Optional gatewayHost?: string

        the hostname of an IPFS HTTP gateway to use in metadata links. Defaults to "nftstorage.link" if not set.

      • Optional validateSchema?: boolean

        if true, validate the metadata against a JSON schema before processing. off by default

    Returns Promise<PackagedNFT>

    on success, a PackagedNFT object containing the parsed metadata and the CAR data to upload to NFT.Storage.

  • makeMetaplexUploadToken(auth: AuthContext, rootCID: string): Promise<string>
  • Encodes the given NFT metadata and asset files into CARs that can be uploaded to NFT.Storage.

    First, the imageFile and any additionalAssetFiles are packed into a CAR, and the root CID of this "asset CAR" is used to create IPFS URIs and gateway URLs for each file in the NFT bundle.

    The input metadata is then modified:

    • The image field is set to an HTTP gateway URL for the imageFile
    • If animation_url contains a filename that matches the name of any of the additionalAssetFiles, its value will be set to an HTTP gateway URL for that file.
    • If any entries in properties.files have a uri that matches the name of imageFile or any of the additionalAssetFiles, it will be replaced by two entries in the output metadata. One will contain an ipfs:// uri with cdn == false, and the other will have an HTTP gateway URL, with cdn == true.

    This updated metadata is then serialized and packed into a second car. Both CARs are returned in a PackagedNFT object, which also contains the updated metadata object and links to the metadata.

    Note that this function does NOT store anything with NFT.Storage. The links in the returned PackagedNFT will not resolve until the CARs have been uploaded. Use NFTStorageMetaplexor.storePreparedNFT to upload.

    Parameters

    • metadata: Record<string, any>

      a JS object containing (hopefully) valid Metaplex NFT metadata

    • imageFile: <internal>.File

      a File object containing image data.

    • opts: { additionalAssetFiles?: <internal>.File[]; blockstore?: <internal>.Blockstore; gatewayHost?: string; validateSchema?: boolean } = {}
      • Optional additionalAssetFiles?: <internal>.File[]

        any additional asset files (animations, higher resolution variants, etc)

      • Optional blockstore?: <internal>.Blockstore

        blockstore to use when importing data. if not provided, a temporary blockstore will be created

      • Optional gatewayHost?: string

        the hostname of an IPFS HTTP gateway to use in metadata links. Defaults to "nftstorage.link" if not set.

      • Optional validateSchema?: boolean

        if true, validate the metadata against a JSON schema before processing. off by default

    Returns Promise<PackagedNFT>

Generated using TypeDoc